YoggieEngine/SandboxApplication/Sandbox.cpp

62 lines
1.6 KiB
C++
Raw Normal View History

#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();
2022-05-04 12:39:27 +00:00
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;
2022-05-04 12:39:27 +00:00
glm::mat4 projection = glm::perspective(glm::radians(cam->Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
2022-05-04 12:39:27 +00:00
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());
2022-05-04 12:39:27 +00:00
Cube->Draw();
}
2022-04-30 18:20:07 +00:00
void Stop() {
2022-05-04 12:39:27 +00:00
// Cleanup
Cube->VAO.Delete();
Cube->elementBuffer.Delete();
delete Cube;
delete cam;
delete shader;
}