2022-05-28 11:32:17 +00:00
|
|
|
#include "BarinkEngine.h"
|
2022-05-28 16:49:08 +00:00
|
|
|
using namespace BarinkEngine;
|
2022-05-28 11:32:17 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
Camera* cam;
|
|
|
|
Renderable* Cube;
|
|
|
|
Shader* shader;
|
2022-05-28 11:32:17 +00:00
|
|
|
|
2022-05-04 21:25:18 +00:00
|
|
|
|
2022-05-27 20:47:36 +00:00
|
|
|
void Start(int argc, char* argv[]) {
|
|
|
|
std::cout << "Hello start!" << std::endl;
|
2022-05-28 16:49:08 +00:00
|
|
|
|
2022-05-04 09:10:26 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
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
|
|
|
|
2022-05-04 21:25:18 +00:00
|
|
|
|
|
|
|
spdlog::info("==== Load Shader(s) ====");
|
2022-04-22 20:37:38 +00:00
|
|
|
std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
|
|
|
|
std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
|
2022-05-28 16:49:08 +00:00
|
|
|
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
2022-05-04 13:27:42 +00:00
|
|
|
|
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
}
|
2022-05-13 19:59:19 +00:00
|
|
|
|
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
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));
|
2022-05-13 19:59:19 +00:00
|
|
|
|
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
glm::mat4 model = tran * rot * scale;
|
2022-05-04 12:39:27 +00:00
|
|
|
|
2022-05-28 16:49:08 +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
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2022-05-13 19:59:19 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
shader->Use();
|
|
|
|
shader->setUniformMat4("P", projection);
|
|
|
|
shader->setUniformMat4("M", model);
|
|
|
|
shader->setUniformMat4("V", cam->GetViewMatrix());
|
2022-05-04 12:39:27 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
Cube->Draw();
|
2022-05-04 09:10:26 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
}
|
2022-05-04 09:10:26 +00:00
|
|
|
|
2022-04-30 18:20:07 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
void Stop() {
|
2022-05-04 12:39:27 +00:00
|
|
|
// Cleanup
|
2022-05-28 16:49:08 +00:00
|
|
|
Cube->VAO.Delete();
|
|
|
|
Cube->elementBuffer.Delete();
|
2022-04-20 19:40:35 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
delete Cube;
|
|
|
|
delete cam;
|
|
|
|
delete shader;
|
|
|
|
}
|