Working on basic rendering #4
* Added a basic material abstraction * Started implementation of RenderTarget (such as render textures)
This commit is contained in:
@ -1,31 +1,35 @@
|
||||
#include "GUI.h"
|
||||
|
||||
void CameraTool(Camera* cam) {
|
||||
|
||||
ImGui::Begin("Camera");
|
||||
|
||||
ImGui::SliderFloat("Zoom:", &cam->Zoom, 10, 190);
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ScriptingTool(char* code) {
|
||||
ImGui::Begin("Scripting");
|
||||
|
||||
ImGui::InputTextMultiline("Lua Script", code, 255);
|
||||
bool runCode = ImGui::Button("Run");
|
||||
|
||||
|
||||
ImGui::End();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void transformWindow(Transform& transform, std::string PanelName) {
|
||||
ImGui::Begin(PanelName.c_str());
|
||||
ImGui::InputFloat3("Position:", (float*)&transform.Position[0]);
|
||||
ImGui::InputFloat3("Rotation:", (float*)&transform.Rotation[0]);
|
||||
ImGui::InputFloat3("Scale:", (float*)&transform.Scale[0]);
|
||||
ImGui::End();
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
void CameraTool(Camera* cam) {
|
||||
|
||||
ImGui::Begin("Camera");
|
||||
|
||||
ImGui::SliderFloat("Zoom:", &cam->Zoom, 10, 190);
|
||||
|
||||
ImGui::InputFloat3("Position:", &cam->Position[0]);
|
||||
|
||||
ImGui::InputFloat3("Rotation:", &cam->Rotation[0]);
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ScriptingTool(char* code) {
|
||||
ImGui::Begin("Scripting");
|
||||
|
||||
ImGui::InputTextMultiline("Lua Script", code, 255);
|
||||
bool runCode = ImGui::Button("Run");
|
||||
|
||||
|
||||
ImGui::End();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void transformWindow(Transform& transform, std::string PanelName) {
|
||||
ImGui::Begin(PanelName.c_str());
|
||||
ImGui::InputFloat3("Position:", (float*)&transform.Position[0]);
|
||||
ImGui::InputFloat3("Rotation:", (float*)&transform.Rotation[0]);
|
||||
ImGui::InputFloat3("Scale:", (float*)&transform.Scale[0]);
|
||||
ImGui::End();
|
||||
|
||||
}
|
@ -1,143 +1,155 @@
|
||||
#include "BarinkEngine.h"
|
||||
#include "imgui.h"
|
||||
#include "GUI.h"
|
||||
#include "Util.h"
|
||||
|
||||
/*
|
||||
* Define globals
|
||||
*/
|
||||
Camera* cam;
|
||||
Renderable* Cube;
|
||||
Renderable* Cube2;
|
||||
|
||||
Shader* shader;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
/*
|
||||
* load meshes
|
||||
*/
|
||||
Cube = Renderable::Load();
|
||||
Cube2 = Renderable::Load();
|
||||
Cube->addChild(*Cube2);
|
||||
|
||||
cam = new Camera(glm::vec3(0.0f, 1.5f, -10.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)");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 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());
|
||||
shader->setUniformVec3("MatColour", glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
|
||||
Cube->Draw();
|
||||
|
||||
shader->setUniformMat4("M", CalculateModelMat(Cube2->transform));
|
||||
shader->setUniformVec3("MatColour", glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
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 shader;
|
||||
#include "BarinkEngine.h"
|
||||
#include "imgui.h"
|
||||
#include "GUI.h"
|
||||
#include "Util.h"
|
||||
|
||||
/*
|
||||
* Define globals
|
||||
*/
|
||||
Camera* cam;
|
||||
Renderable* Cube;
|
||||
Renderable* Cube2;
|
||||
|
||||
Shader* shader;
|
||||
Material* matCube;
|
||||
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);
|
||||
|
||||
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 = Renderable::Load();
|
||||
Cube2 = Renderable::Load();
|
||||
Cube->addChild(*Cube2);
|
||||
|
||||
cam = new Camera(glm::vec3(0.0f, 1.5f, -10.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)");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
Reference in New Issue
Block a user