1
0

Rendering sprites

This commit is contained in:
2022-10-19 17:30:18 +02:00
parent e211fb13c3
commit d1963f08c6
8 changed files with 138 additions and 4 deletions

View File

@@ -1,18 +1,32 @@
#include "game.h"
#include <iostream>
SpriteRenderer* Renderer;
Game::~Game()
{
delete Renderer;
}
Game::Game(unsigned int width, unsigned int height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height)
{
}
void Game::Init()
{
// Load shaders
ResourceManager::LoadShader("shader.vs", "shader.fs", nullptr, "sprite");
// configure shaders
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(this->Width), static_cast<float>(this->Height), 0.0f, -1.0f, 1.0f);
ResourceManager::GetShader("sprite").Use().SetInteger("image", 0);
ResourceManager::GetShader("sprite").SetMatrix4("projection", projection);
// set render-specific controls
Renderer = new SpriteRenderer(ResourceManager::GetShader("sprite"));
// load textures
ResourceManager::LoadTexture("textures/awesomeface.png", true, "face");
}
@@ -29,5 +43,5 @@ void Game::Update(float dt)
void Game::Render()
{
Renderer->DrawSprite(ResourceManager::GetTexture("face"), glm::vec2(200.0f, 200.0f), glm::vec2(300.0f, 400.0f), 45.0f, glm::vec3(0.0f, 1.0f,0.0f));
}