2022-11-03 19:33:14 +00:00
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
#include "stb_image.h"
|
|
|
|
#include "../../libs/guizmo/ImGuizmo.h"
|
|
|
|
|
2022-10-22 13:21:48 +00:00
|
|
|
#include "../../BarinkEngine/src/BarinkEngine.h"
|
|
|
|
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
|
2022-11-03 14:06:42 +00:00
|
|
|
#include "../../BarinkEngine/src/Graphics/Memory/Framebuffer.h"
|
|
|
|
#include "../../BarinkEngine/src/PerfCounter.cpp"
|
|
|
|
#include "../../BarinkEngine/src/Scene/Entity.h"
|
2022-11-03 19:33:14 +00:00
|
|
|
#include "Widgets.h"
|
|
|
|
|
2022-10-22 13:21:48 +00:00
|
|
|
/*
|
|
|
|
* Define globals
|
|
|
|
*/
|
|
|
|
|
|
|
|
Framebuffer* framebuffer;
|
2022-11-03 14:06:42 +00:00
|
|
|
Scene Level1;
|
|
|
|
BarinkEngine::SceneObject* Model;
|
|
|
|
Entity cube;
|
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
entt::entity Selected;
|
2022-10-22 13:21:48 +00:00
|
|
|
/*
|
|
|
|
* Runs once at startup
|
|
|
|
* - USe to initialize the game/sandbox/demo
|
|
|
|
*/
|
|
|
|
void Start() {
|
2022-11-03 14:06:42 +00:00
|
|
|
auto io = ImGui::GetIO();
|
|
|
|
io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18);
|
2022-11-03 19:33:14 +00:00
|
|
|
|
2022-11-03 14:06:42 +00:00
|
|
|
framebuffer = new Framebuffer();
|
2022-11-03 19:33:14 +00:00
|
|
|
|
2022-10-22 13:21:48 +00:00
|
|
|
|
|
|
|
// Create a level and load it as the current level
|
2022-11-03 14:06:42 +00:00
|
|
|
auto importer = BarinkEngine::ModelImporter();
|
|
|
|
|
|
|
|
// Create a cube
|
|
|
|
Model = importer.Import("build/Debug/Models/Cube.obj");
|
|
|
|
cube = Level1.AddEntity("cube");
|
2022-11-03 19:33:14 +00:00
|
|
|
|
2022-11-03 14:06:42 +00:00
|
|
|
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
|
|
|
|
render3DComponent.mesh = *(Model->renderable->mesh);
|
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
cube.GetComponent<BarinkEngine::TransformComponent>().Position = glm::vec3(1.0f, 0.0f, 5.0f);
|
2022-11-03 14:06:42 +00:00
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
auto cube2 = Level1.AddEntity("Cube1");
|
|
|
|
auto& rendercube2 = cube2.AddComponent<BarinkEngine::Render3DComponent>();
|
|
|
|
rendercube2.mesh = *(Model->renderable->mesh);
|
|
|
|
|
2022-10-22 13:21:48 +00:00
|
|
|
|
2022-11-03 14:06:42 +00:00
|
|
|
// create an ambient light source
|
|
|
|
auto AmbientLight = Level1.AddEntity("AmbientLight");
|
2022-11-03 19:33:14 +00:00
|
|
|
auto light = AmbientLight.AddComponent<BarinkEngine::LightComponent>();
|
|
|
|
light.Color = glm::vec3(1.0f);
|
|
|
|
light.Strength = 1.0f;
|
2022-10-22 13:21:48 +00:00
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
Selected = (entt::entity) -1;
|
2022-10-22 13:21:48 +00:00
|
|
|
|
2022-11-03 14:06:42 +00:00
|
|
|
renderer.Prepare(Level1);
|
2022-10-22 13:21:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Runs every frame
|
|
|
|
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
|
|
|
*/
|
|
|
|
void ImmediateGraphicsDraw()
|
2022-11-03 14:06:42 +00:00
|
|
|
{ ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
2022-10-22 13:21:48 +00:00
|
|
|
|
|
|
|
// Show a menu bar
|
|
|
|
ImGui::BeginMainMenuBar();
|
|
|
|
|
|
|
|
if (ImGui::BeginMenu("Application")) {
|
|
|
|
|
2022-11-03 14:06:42 +00:00
|
|
|
if (ImGui::MenuItem("Preferences")) {
|
|
|
|
|
|
|
|
}
|
2022-10-22 13:21:48 +00:00
|
|
|
|
|
|
|
if (ImGui::MenuItem("Exit")) {
|
|
|
|
// TODO: Exit application
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
if (ImGui::BeginMenu("Scene")) {
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::MenuItem("Add Entity")) {
|
|
|
|
Level1.AddEntity("New entity");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2022-10-22 13:21:48 +00:00
|
|
|
|
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
ImGui::EndMainMenuBar();
|
|
|
|
|
2022-11-03 14:06:42 +00:00
|
|
|
//ShowStats();
|
2022-11-03 19:33:14 +00:00
|
|
|
Viewport(*framebuffer, Level1);
|
|
|
|
SceneExplorer(Selected, Level1);
|
|
|
|
Inspector(Selected, Level1 );
|
|
|
|
|
2022-11-03 14:06:42 +00:00
|
|
|
Settings();
|
|
|
|
AssetsFinder();
|
|
|
|
Console();
|
2022-10-22 13:21:48 +00:00
|
|
|
|
2022-11-03 19:33:14 +00:00
|
|
|
ImGui::ShowDemoWindow();
|
2022-11-03 14:06:42 +00:00
|
|
|
ImGui::ShowMetricsWindow();
|
|
|
|
|
2022-10-22 13:21:48 +00:00
|
|
|
|
2022-11-03 14:06:42 +00:00
|
|
|
}
|
2022-10-22 13:21:48 +00:00
|
|
|
|
2022-11-03 14:06:42 +00:00
|
|
|
void Render()
|
|
|
|
{
|
|
|
|
renderer.Render( *framebuffer, Level1);
|
2022-10-22 13:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Runs every frame
|
|
|
|
* - Meant for game logic ( non-physics related)
|
|
|
|
*/
|
|
|
|
void Update()
|
2022-10-22 12:58:55 +00:00
|
|
|
{
|
2022-11-03 14:06:42 +00:00
|
|
|
}
|
2022-10-22 12:58:55 +00:00
|
|
|
|
2022-11-03 14:06:42 +00:00
|
|
|
/*
|
|
|
|
* Runs every physics update
|
|
|
|
*/
|
|
|
|
void fixed_update()
|
|
|
|
{
|
|
|
|
|
2022-10-22 13:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Runs at the end of the program
|
|
|
|
* - Meant for cleanup
|
|
|
|
*/
|
|
|
|
void Stop()
|
|
|
|
{
|
|
|
|
delete framebuffer;
|
2022-10-22 12:58:55 +00:00
|
|
|
}
|