71 lines
1.4 KiB
C++
71 lines
1.4 KiB
C++
// Copyright (c) 2024 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "Game.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
|
|
Game::Game() :
|
|
renderManager()
|
|
{
|
|
|
|
}
|
|
|
|
std::shared_ptr<Scene> Game::getCurrentScene() {
|
|
return currentScene;
|
|
}
|
|
|
|
void Game::setCurrentScene(std::shared_ptr<Scene> scene) {
|
|
currentScene = scene;
|
|
}
|
|
|
|
void Game::init() {
|
|
renderManager.init(*this);
|
|
|
|
this->shader = std::make_shared<SimpleTexturedShader>();
|
|
this->shader->init();
|
|
this->shader->bind();
|
|
|
|
this->mesh = std::make_shared<Mesh>();
|
|
this->mesh->createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
|
|
QuadMesh::buffer(this->mesh, glm::vec4(-0.5f, -0.5f, 0.5f, 0.5f), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), 0, 0);
|
|
}
|
|
|
|
void Game::update() {
|
|
renderManager.update(*this);
|
|
|
|
glm::mat4 view = glm::lookAt(
|
|
glm::vec3(3, 3, 3),
|
|
glm::vec3(0, 0, 0),
|
|
glm::vec3(0, 1, 0)
|
|
);
|
|
|
|
glm::mat4 proj = glm::perspective(
|
|
glm::radians(45.0f),
|
|
800.0f / 600.0f,
|
|
0.1f,
|
|
100.0f
|
|
);
|
|
|
|
glm::mat4 model = glm::mat4(1.0f);
|
|
|
|
this->shader->bind();
|
|
this->shader->setData(SimpleTexturedShaderData {
|
|
.projection = proj,
|
|
.view = view,
|
|
.model = model,
|
|
.color = COLOR_WHITE,
|
|
.hasTexture = false,
|
|
.texture = 0
|
|
});
|
|
this->shader->upload();
|
|
this->mesh->draw(MeshDrawMode::TRIANGLES, 0, QUAD_INDICE_COUNT);
|
|
}
|
|
|
|
Game::~Game() {
|
|
shader = nullptr;
|
|
mesh = nullptr;
|
|
} |