YoggieEngine/SandboxApplication/Sandbox.cpp

170 lines
3.8 KiB
C++

#include "BarinkEngine.h"
#include "Scene\SceneManager.h"
#include "Scene\SceneNodeTypes.h"
#include "AssetManager/ModelImporter.h"
#include "imgui.h"
#include "GUI.h"
#include "Util.h"
/*
* Define globals
*/
Camera* cam;
Shader* shader;
//BarinkEngine::Renderable* Cube;
//Material* matCube;
//Texture* textureCube;
//BarinkEngine::Renderable* Cube2;
//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";
ModelImporter* MI = new ModelImporter();
/*
* Runs once at startup
* - USe to initialize the game/sandbox/demo
*/
void Start() {
// Create a level and load it as the current level
auto Level1 = SceneManager::CreateScene("TestLevel");
SceneManager::LoadScene(*Level1);
// Create a cube node
Level1->GetRoot().addChild(*(MI->Import("build/SandboxApplication/Debug/Models")));
// Build a basic test scene
// NOTE: This will later be done through an editor
// Walk scene graph
PrintSceneTree(Level1->GetRoot(),0);
shader = new Shader(vertexShaderSource, fragmentShaderSource);
//textureCube = new Texture("build/SandboxApplication/Debug/Textures/wall.jpg");
//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);
/*
* load meshes
*/
//Cube =
//Cube2 = Renderable::Load();
//Cube->addChild(*Cube2);
//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);
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)");
//materialWindow(*matCube, "Material Cube");
//materialWindow(*matCube2, "Material Cube2");
}
/*
* 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;
}