Sandbox App is no longer an editor, Editor setup has moved to the editor project

This commit is contained in:
Nigel Barink 2022-10-22 15:21:48 +02:00
parent 955eeabb48
commit 23ac663667
5 changed files with 180 additions and 42 deletions

View File

@ -35,28 +35,7 @@ void GUIManager::Render()
ImGui::NewFrame();
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
ImGui::Begin("##App");
// Show a menu bar
ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("Application")) {
if (ImGui::MenuItem("Exit")) {
// TODO: Exit application
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
ImmediateGraphicsDraw();
ImGui::End();

View File

@ -22,6 +22,49 @@ BarinkEngine::Renderer::~Renderer()
// glDeleteBuffers(1, &UV_id);
}
void BarinkEngine::Renderer::Render()
{
Angle += 0.0001f;
for (auto model : models) {
// Push matrices etc ....
model->vertexarray.Bind();
model->elementBuffer.Bind(true);
if (model->material == nullptr) {
std::cout << "No material attached!" << std::endl;
// continue; //NOTE: Or use some default Material
}
else {
model->material->shader.Use();
model->material->Apply();
model->material->shader.setUniformVec3("Color", model->material->Color);
model->material->shader.setUniformMat4("M", glm::rotate(glm::mat4(), Angle, glm::vec3(0.5f, 0.5f, 0.0f)));
model->material->shader.setUniformMat4("V", cam.GetViewMatrix());
model->material->shader.setUniformMat4("P", projection);
// Update perf counters
ES.verts = model->mesh->vertices.size();
ES.DC++;
glDrawElements(GL_TRIANGLES,
static_cast<unsigned int>(model->mesh->elements.size()),
GL_UNSIGNED_INT,
NULL
);
}
model->vertexarray.Unbind();
}
}
void BarinkEngine::Renderer::Render(Framebuffer& framebuffer)
{
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.GetId());

View File

@ -19,6 +19,8 @@ namespace BarinkEngine {
Renderer();
~Renderer();
void Render();
void Render(Framebuffer& framebuffer);
void Submit(Renderable* model);

View File

@ -1,8 +1,138 @@
#include <iostream>
#include "../../BarinkEngine/src/BarinkEngine.h"
#include "../../BarinkEngine/src/Scene/SceneManager.h"
#include "../../BarinkEngine/src/Scene/SceneNodeTypes.h"
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
#include "../../BarinkEngine/src/Graphics/Framebuffer.h"
#include <imgui.h>
/*
* Define globals
*/
Shader* shader;
int main()
{
std::cout << "Welcome to the Editor!" << std::endl;
char* code = new char[254];
const std::string vertexShaderSource = "build/Debug/test.vs";
const std::string fragmentShaderSource = "build/Debug/test.fs";
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
Framebuffer* framebuffer;
Scene* Level1;
BarinkEngine::SceneObject* cube;
/*
* Runs once at startup
* - USe to initialize the game/sandbox/demo
*/
void Start() {
// Build a basic test scene
// NOTE: This will later be done through an editor
// Create a level and load it as the current level
std::string levelName("Test Level");
Level1 = SceneManager::CreateScene(levelName);
SceneManager::LoadScene(*Level1);
shader = new Shader(vertexShaderSource, fragmentShaderSource);
// Create a cube node
cube = MI->Import("build/Debug/Models/cube.obj");
cube->renderable->material = new Material(*shader);
cube->renderable->material->Color = glm::vec3(1.0f, 0.0f, 0.0f);
// What is in cube now ??
std::cout << "mesh vertices: " << cube->renderable->mesh->vertices.size() << std::endl;
std::cout << "mesh elements: " << cube->renderable->mesh->elements.size() << std::endl;
Level1->GetRoot().addChild(*cube);
memset(code, '\0', 254);
framebuffer = new Framebuffer();
std::cout << "Colour attachment id; " << framebuffer->GetColourAttachment() << std::endl;
// TODO: Move to runtime/ Engine
// NOTE: Submits should later be done through walking the sceneTree
renderer.Submit(cube->renderable);
}
/*
* Runs every frame
* - Use to draw Immediate mode graphics (Not meant for HUD's )
*/
void ImmediateGraphicsDraw()
{
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
// Show a menu bar
ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("Application")) {
if (ImGui::MenuItem("Exit")) {
// TODO: Exit application
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
// Show internal BarinkEngine stats
ShowStats();
ImGui::Begin("Viewport");
ImGui::Image((void*)(intptr_t)framebuffer->GetColourAttachment(), ImVec2{ 800,600 });
ImGui::End();
static float Zoom = 90;
static glm::vec3 Position = glm::vec3(0.0f, 0.0f, 0.0f);
static glm::vec3 Rotation = glm::vec3(0.0f, 0.0f, 0.0f);
ImGui::Begin("Camera");
ImGui::SliderFloat("Zoom", &Zoom, 10, 190);
ImGui::InputFloat3("Position:", &Position[0]);
ImGui::InputFloat3("Rotation:", &Rotation[0]);
ImGui::End();
ImGui::Begin("Scripting");
ImGui::Text("Lua Code");
ImGui::InputTextMultiline("##", code, 255);
bool runCode = ImGui::Button("Run");
ImGui::End();
ImGui::Begin("Scene Explorer");
ImGui::End();
}
/*
* Runs every frame
* - Meant for game logic ( non-physics related)
*/
void Update()
{
// glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->GetId());
renderer.Render(*framebuffer);
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
/*
* Runs at the end of the program
* - Meant for cleanup
*/
void Stop()
{
delete framebuffer;
delete MI;
delete shader;
}

View File

@ -18,7 +18,6 @@ const std::string vertexShaderSource = "build/Debug/test.vs";
const std::string fragmentShaderSource = "build/Debug/test.fs";
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
Framebuffer* framebuffer;
Scene* Level1;
BarinkEngine::SceneObject* cube;
/*
@ -26,8 +25,6 @@ BarinkEngine::SceneObject* cube;
* - USe to initialize the game/sandbox/demo
*/
void Start() {
// Build a basic test scene
// NOTE: This will later be done through an editor
// Create a level and load it as the current level
std::string levelName("Test Level");
@ -49,9 +46,7 @@ void Start() {
Level1->GetRoot().addChild(*cube);
memset(code, '\0', 254);
framebuffer = new Framebuffer();
std::cout << "Colour attachment id; "<< framebuffer->GetColourAttachment() << std::endl;
// TODO: Move to runtime/ Engine
// NOTE: Submits should later be done through walking the sceneTree
@ -67,14 +62,6 @@ void ImmediateGraphicsDraw()
{
// Show internal BarinkEngine stats
ShowStats();
SceneView(*framebuffer);
// Show different tooling for this specific sandbox
CameraTool();
ScriptingTool(code);
SceneExplorer( "Scene Explorer");
}
/*
@ -83,11 +70,9 @@ void ImmediateGraphicsDraw()
*/
void Update()
{
// glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->GetId());
renderer.Render(*framebuffer);
renderer.Render();
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
/*
@ -96,7 +81,6 @@ void Update()
*/
void Stop()
{
delete framebuffer;
delete MI;
delete shader;
}