YoggieEngine/SandboxApplication/Sandbox.cpp
nigel 76c051e407 Made multiple managers for individual pieces
Added UIManager that renders the UI inside the window
2022-05-28 18:49:08 +02:00

62 lines
1.6 KiB
C++

#include "BarinkEngine.h"
using namespace BarinkEngine;
Camera* cam;
Renderable* Cube;
Shader* shader;
void Start(int argc, char* argv[]) {
std::cout << "Hello start!" << std::endl;
cam = new Camera (glm::vec3(0.0f, 1.5f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
Cube = &Renderable::Load();
spdlog::info("==== Load Shader(s) ====");
std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
shader = new Shader(vertexShaderSource, fragmentShaderSource);
}
void Update()
{
glm::mat4 tran = glm::translate(glm::mat4(), Cube->transform.Position);
glm::mat4 scale = glm::scale(glm::mat4(), Cube->transform.Scale);
glm::mat4 rot =
glm::rotate(glm::mat4(), glm::radians(Cube->transform.Rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)) *
glm::rotate(glm::mat4(), glm::radians(Cube->transform.Rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)) *
glm::rotate(glm::mat4(), glm::radians(Cube->transform.Rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
glm::mat4 model = tran * rot * scale;
glm::mat4 projection = glm::perspective(glm::radians(cam->Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
shader->Use();
shader->setUniformMat4("P", projection);
shader->setUniformMat4("M", model);
shader->setUniformMat4("V", cam->GetViewMatrix());
Cube->Draw();
}
void Stop() {
// Cleanup
Cube->VAO.Delete();
Cube->elementBuffer.Delete();
delete Cube;
delete cam;
delete shader;
}