2022-06-04 16:26:58 +00:00
|
|
|
#include "BarinkEngine.h"
|
|
|
|
#include "imgui.h"
|
|
|
|
#include "GUI.h"
|
|
|
|
#include "Util.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define globals
|
|
|
|
*/
|
|
|
|
Camera* cam;
|
2022-06-04 23:44:54 +00:00
|
|
|
|
2022-06-04 16:26:58 +00:00
|
|
|
|
|
|
|
Shader* shader;
|
2022-06-04 23:44:54 +00:00
|
|
|
|
|
|
|
Renderable* Cube;
|
2022-06-04 16:26:58 +00:00
|
|
|
Material* matCube;
|
2022-06-04 23:44:54 +00:00
|
|
|
Texture* textureCube;
|
|
|
|
|
|
|
|
Renderable* Cube2;
|
2022-06-04 16:26:58 +00:00
|
|
|
Material* matCube2;
|
|
|
|
|
|
|
|
char* code = new char[254];
|
|
|
|
|
|
|
|
|
|
|
|
const std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
|
|
|
|
const std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Runs once at startup
|
|
|
|
* - USe to initialize the game/sandbox/demo
|
|
|
|
*/
|
|
|
|
void Start() {
|
|
|
|
|
|
|
|
/*
|
|
|
|
Building a very basic scene graph
|
|
|
|
*/
|
|
|
|
SceneNode MyCube = SceneNode();
|
|
|
|
MyCube.name = "MyCube";
|
|
|
|
|
|
|
|
SceneNode MyBaby = SceneNode();
|
|
|
|
MyBaby.name = "Baby";
|
|
|
|
|
|
|
|
SceneNode MySecondCube = SceneNode();
|
|
|
|
MySecondCube.name = "MySecondCube";
|
|
|
|
|
|
|
|
|
|
|
|
MyCube.addChild(MyBaby);
|
|
|
|
|
|
|
|
|
|
|
|
Scene scene = Scene("My awesome Game Scene");
|
|
|
|
scene.GetRoot().addChild(MyCube);
|
|
|
|
scene.GetRoot().addChild(MySecondCube);
|
|
|
|
|
|
|
|
|
|
|
|
// Walk scene graph
|
|
|
|
PrintSceneTree(scene.GetRoot(),0);
|
|
|
|
|
|
|
|
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
|
|
|
|
2022-06-10 19:06:20 +00:00
|
|
|
textureCube = new Texture("build/SandboxApplication/Debug/Textures/wall.jpg");
|
2022-06-04 23:44:54 +00:00
|
|
|
|
2022-06-04 16:26:58 +00:00
|
|
|
matCube = new Material(*shader);
|
|
|
|
matCube->Color = glm::vec3(1.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
matCube2 = new Material(*shader);
|
|
|
|
matCube2->Color = glm::vec3(0.0, 1.0f, 0.0);
|
|
|
|
|
2022-06-19 18:01:31 +00:00
|
|
|
std::string cubePath = "build/SandboxApplication/Debug/Models/Cube.obj";
|
|
|
|
std::string lanternPath = "build/SandboxApplication/Debug/Models/Latern.gltf";
|
2022-06-04 16:26:58 +00:00
|
|
|
/*
|
|
|
|
* load meshes
|
|
|
|
*/
|
2022-06-19 18:01:31 +00:00
|
|
|
Cube = Renderable::Load(lanternPath);
|
|
|
|
Cube2 = Renderable::Load(cubePath);
|
2022-06-04 16:26:58 +00:00
|
|
|
Cube->addChild(*Cube2);
|
|
|
|
|
2022-06-04 23:44:54 +00:00
|
|
|
Cube->shader = shader;
|
|
|
|
Cube2->shader = shader;
|
|
|
|
|
|
|
|
Cube->texture = textureCube;
|
|
|
|
Cube2->texture = textureCube;
|
|
|
|
|
|
|
|
Cube2->transform.Position = glm::vec3(-9.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
Cube->transform.Position = glm::vec3(-8.0f, 0.0f, -2.0f);
|
|
|
|
|
|
|
|
cam = new Camera(glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
2022-06-04 16:26:58 +00:00
|
|
|
|
|
|
|
memset(code, '\0', 254);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Runs every frame
|
|
|
|
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
|
|
|
*/
|
|
|
|
void ImmediateGraphicsDraw() {
|
|
|
|
ImGui::NewFrame();
|
|
|
|
|
|
|
|
// Show ImGui demo such that I can easily look
|
|
|
|
// at possible GUI elements to use
|
|
|
|
ImGui::ShowDemoWindow();
|
|
|
|
|
|
|
|
|
|
|
|
// Show internal BarinkEngine stats
|
|
|
|
ShowStats();
|
|
|
|
|
|
|
|
|
|
|
|
// Show different tooling for this specific sandbox
|
|
|
|
CameraTool(cam);
|
|
|
|
ScriptingTool(code);
|
|
|
|
|
|
|
|
transformWindow(Cube->transform, "Transform (Cube)");
|
|
|
|
|
|
|
|
transformWindow(Cube2->transform, "Transform (Cube2)");
|
|
|
|
|
2022-06-04 23:44:54 +00:00
|
|
|
materialWindow(*matCube, "Material Cube");
|
|
|
|
materialWindow(*matCube2, "Material Cube2");
|
|
|
|
|
2022-06-04 16:26:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Runs every frame
|
|
|
|
* - Meant for game logic ( non-physics related)
|
|
|
|
*/
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: this needs to move to the renderer
|
|
|
|
* Render code should not appear in the sandbox file
|
|
|
|
*/
|
|
|
|
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", CalculateModelMat(Cube->transform));
|
|
|
|
shader->setUniformMat4("V", cam->GetViewMatrix());
|
|
|
|
matCube->Apply();
|
|
|
|
|
|
|
|
Cube->Draw();
|
|
|
|
|
|
|
|
shader->setUniformMat4("M", CalculateModelMat(Cube2->transform));
|
|
|
|
matCube2->Apply();
|
|
|
|
|
|
|
|
Cube2->Draw();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Runs at the end of the program
|
|
|
|
* - Meant for cleanup
|
|
|
|
*/
|
|
|
|
void Stop() {
|
|
|
|
// Cleanup
|
|
|
|
Cube->VAO.Delete();
|
|
|
|
Cube->elementBuffer.Delete();
|
|
|
|
|
|
|
|
Cube2->VAO.Delete();
|
|
|
|
Cube2->elementBuffer.Delete();
|
|
|
|
|
|
|
|
delete Cube2;
|
|
|
|
delete Cube;
|
|
|
|
|
|
|
|
delete matCube;
|
|
|
|
delete matCube2;
|
|
|
|
|
|
|
|
delete shader;
|
2022-05-28 16:49:08 +00:00
|
|
|
}
|