diff --git a/.gitignore b/.gitignore index 89f9fb2..a7600e4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ build/ *.exe *.o .vscode/ -*.ini diff --git a/imgui.ini b/imgui.ini new file mode 100644 index 0000000..aa8a1b8 --- /dev/null +++ b/imgui.ini @@ -0,0 +1,59 @@ +[Window][DockSpace] +Pos=0,0 +Size=1920,1177 +Collapsed=0 + +[Window][Debug##Default] +Pos=60,60 +Size=400,400 +Collapsed=0 + +[Window][Inspector] +Pos=1588,27 +Size=324,772 +Collapsed=0 +DockId=0x00000005,0 + +[Window][OpenGL Output] +Pos=375,27 +Size=1211,770 +Collapsed=0 +DockId=0x00000003,0 + +[Window][Performance] +Pos=1588,801 +Size=324,368 +Collapsed=0 +DockId=0x00000006,0 + +[Window][Logger] +Pos=375,799 +Size=1211,370 +Collapsed=0 +DockId=0x00000004,0 + +[Window][Object Selector] +Pos=8,27 +Size=357,1142 +Collapsed=0 +DockId=0x00000007,0 + +[Window][Scene Window] +Pos=8,27 +Size=365,1142 +Collapsed=0 +DockId=0x00000009,0 + +[Docking][Data] +DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1904,1142 Split=X Selected=0xF7365A5A + DockNode ID=0x00000009 Parent=0x14621557 SizeRef=365,1142 Selected=0x3DC5AC3F + DockNode ID=0x0000000A Parent=0x14621557 SizeRef=1537,1142 Split=X + DockNode ID=0x00000007 Parent=0x0000000A SizeRef=357,1142 Selected=0x7737E8B2 + DockNode ID=0x00000008 Parent=0x0000000A SizeRef=1545,1142 Split=X + DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1211,1142 Split=Y Selected=0xF7365A5A + DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1578,770 CentralNode=1 HiddenTabBar=1 Selected=0xF7365A5A + DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1578,370 HiddenTabBar=1 Selected=0x9DD4E196 + DockNode ID=0x00000002 Parent=0x00000008 SizeRef=324,1142 Split=Y Selected=0x36DC96AB + DockNode ID=0x00000005 Parent=0x00000002 SizeRef=324,772 HiddenTabBar=1 Selected=0x36DC96AB + DockNode ID=0x00000006 Parent=0x00000002 SizeRef=324,368 HiddenTabBar=1 Selected=0x726D8899 + diff --git a/src/Engine.cpp b/src/Engine.cpp index 9b18753..b53e478 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -4,7 +4,7 @@ // Settings -#define VSync 0 +#define VSync 1 #include "Engine.h" #include @@ -21,6 +21,17 @@ #include "Windows/PerformanceWindow.h" #include "Windows/LoggerWindow.h" #include "Windows/InspectorWindow.h" +#include "Windows/SceneWindow.h" + + +#define YAML_CPP_STATIC_DEFINE +#include + + + +#include "TestModel.h" + + @@ -31,7 +42,11 @@ AssetManager g_AssetManager; LoggerWindow *g_LoggerWindow; -std::vector m_GameObjects; +std::vector g_GameObjects; + +GameObject* g_SelectedObject; // Pointer to the currently selected object + + bool MyEngine::Init(int width, int height, const std::string& title) @@ -95,7 +110,7 @@ bool MyEngine::Init(int width, int height, const std::string& title) m_PerformanceWindow = std::make_unique(); m_LoggerWindow = std::make_unique(); m_InspectorWindow = std::make_unique(); - + m_SceneWindow = std::make_unique(); // Some initial logs @@ -111,104 +126,6 @@ bool MyEngine::Init(int width, int height, const std::string& title) return true; } -GLuint CreateCubeVAO() -{ - // Define cube vertices (Position + UVs) - static float g_CubeVertices[] = - { - // Front face - -1.f, -1.f, 1.f, 0.f, 0.f, - 1.f, -1.f, 1.f, 1.f, 0.f, - 1.f, 1.f, 1.f, 1.f, 1.f, - -1.f, 1.f, 1.f, 0.f, 1.f, - - // Back face - -1.f, -1.f, -1.f, 1.f, 0.f, - 1.f, -1.f, -1.f, 0.f, 0.f, - 1.f, 1.f, -1.f, 0.f, 1.f, - -1.f, 1.f, -1.f, 1.f, 1.f, - - // Left face - -1.f, -1.f, -1.f, 0.f, 0.f, - -1.f, -1.f, 1.f, 1.f, 0.f, - -1.f, 1.f, 1.f, 1.f, 1.f, - -1.f, 1.f, -1.f, 0.f, 1.f, - - // Right face - 1.f, -1.f, -1.f, 1.f, 0.f, - 1.f, -1.f, 1.f, 0.f, 0.f, - 1.f, 1.f, 1.f, 0.f, 1.f, - 1.f, 1.f, -1.f, 1.f, 1.f, - - // Top face - -1.f, 1.f, -1.f, 0.f, 0.f, - 1.f, 1.f, -1.f, 1.f, 0.f, - 1.f, 1.f, 1.f, 1.f, 1.f, - -1.f, 1.f, 1.f, 0.f, 1.f, - - // Bottom face - -1.f, -1.f, -1.f, 1.f, 0.f, - 1.f, -1.f, -1.f, 0.f, 0.f, - 1.f, -1.f, 1.f, 0.f, 1.f, - -1.f, -1.f, 1.f, 1.f, 1.f, - }; - - // Define cube indices - static unsigned int g_CubeIndices[] = - { - // Front face - 0, 1, 2, 2, 3, 0, - // Back face - 4, 5, 6, 6, 7, 4, - // Left face - 8, 9, 10, 10, 11, 8, - // Right face - 12, 13, 14, 14, 15, 12, - // Top face - 16, 17, 18, 18, 19, 16, - // Bottom face - 20, 21, 22, 22, 23, 20 - }; - - GLuint VAO, VBO, EBO; - - // Generate and bind VAO - glGenVertexArrays(1, &VAO); - glBindVertexArray(VAO); - - // Generate and bind VBO - glGenBuffers(1, &VBO); - glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(g_CubeVertices), g_CubeVertices, GL_STATIC_DRAW); - - // Generate and bind EBO - glGenBuffers(1, &EBO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(g_CubeIndices), g_CubeIndices, GL_STATIC_DRAW); - - // Define vertex attributes - // Position attribute (location = 0) - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, - 5 * sizeof(float), (void*)0); - glEnableVertexAttribArray(0); - - // UV attribute (location = 1) - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, - 5 * sizeof(float), (void*)(3 * sizeof(float))); - glEnableVertexAttribArray(1); - - // Unbind VAO (not EBO!) - glBindVertexArray(0); - - // Optionally, unbind VBO and EBO for cleanliness - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - - // Debug: Print VAO ID - printf("[MeshUtils] Initialized CubeVAO with ID: %u\n", VAO); - - return VAO; -} void MyEngine::Run() { @@ -217,6 +134,8 @@ void MyEngine::Run() // Pseudocode: GameObject cube; + + cube.name = std::string("Cube"); cube.transform.position = glm::vec3(0.f, 0.f, 0.f); cube.transform.rotation = glm::vec3(0.f, 0.5f, 0.f); cube.transform.scale = glm::vec3(1.f, 1.f, 1.f); @@ -227,7 +146,9 @@ void MyEngine::Run() cube.mesh.indexCount = 36; cube.mesh.textureID = static_cast(reinterpret_cast(g_AssetManager.loadAsset(AssetType::TEXTURE, "assets/textures/wood.png"))); - m_GameObjects.push_back(cube); + g_GameObjects.push_back(cube); + + //printf("%p\n", &g_GameObjects); // Possibly create more GameObjects with different positions or textures @@ -263,6 +184,8 @@ void MyEngine::Run() m_PerformanceWindow->Show(m_Fps, m_Ms); // FPS & ms m_LoggerWindow->Show(); // Logs + m_SceneWindow->Show(); + // After rendering m_PerformanceWindow->UpdatePerformanceStats(-1, -1); diff --git a/src/Engine.h b/src/Engine.h index 5565064..522b43f 100644 --- a/src/Engine.h +++ b/src/Engine.h @@ -8,6 +8,8 @@ #include "Windows/LoggerWindow.h" #include "Engine/AssetManager.h" #include "Windows/InspectorWindow.h" +#include "Windows/SceneWindow.h" + #include "Componenets/GameObject.h" #include "Componenets/Mesh.h" @@ -50,6 +52,8 @@ private: std::unique_ptr m_PerformanceWindow; std::unique_ptr m_LoggerWindow; std::unique_ptr m_InspectorWindow; + std::unique_ptr m_SceneWindow; + // For FPS calculation diff --git a/src/TestModel.cpp b/src/TestModel.cpp new file mode 100644 index 0000000..712144a --- /dev/null +++ b/src/TestModel.cpp @@ -0,0 +1,103 @@ +#include "TestModel.h" +#include +#include + + +GLuint CreateCubeVAO() +{ + // Define cube vertices (Position + UVs) + static float g_CubeVertices[] = + { + // Front face + -1.f, -1.f, 1.f, 0.f, 0.f, + 1.f, -1.f, 1.f, 1.f, 0.f, + 1.f, 1.f, 1.f, 1.f, 1.f, + -1.f, 1.f, 1.f, 0.f, 1.f, + + // Back face + -1.f, -1.f, -1.f, 1.f, 0.f, + 1.f, -1.f, -1.f, 0.f, 0.f, + 1.f, 1.f, -1.f, 0.f, 1.f, + -1.f, 1.f, -1.f, 1.f, 1.f, + + // Left face + -1.f, -1.f, -1.f, 0.f, 0.f, + -1.f, -1.f, 1.f, 1.f, 0.f, + -1.f, 1.f, 1.f, 1.f, 1.f, + -1.f, 1.f, -1.f, 0.f, 1.f, + + // Right face + 1.f, -1.f, -1.f, 1.f, 0.f, + 1.f, -1.f, 1.f, 0.f, 0.f, + 1.f, 1.f, 1.f, 0.f, 1.f, + 1.f, 1.f, -1.f, 1.f, 1.f, + + // Top face + -1.f, 1.f, -1.f, 0.f, 0.f, + 1.f, 1.f, -1.f, 1.f, 0.f, + 1.f, 1.f, 1.f, 1.f, 1.f, + -1.f, 1.f, 1.f, 0.f, 1.f, + + // Bottom face + -1.f, -1.f, -1.f, 1.f, 0.f, + 1.f, -1.f, -1.f, 0.f, 0.f, + 1.f, -1.f, 1.f, 0.f, 1.f, + -1.f, -1.f, 1.f, 1.f, 1.f, + }; + + // Define cube indices + static unsigned int g_CubeIndices[] = + { + // Front face + 0, 1, 2, 2, 3, 0, + // Back face + 4, 5, 6, 6, 7, 4, + // Left face + 8, 9, 10, 10, 11, 8, + // Right face + 12, 13, 14, 14, 15, 12, + // Top face + 16, 17, 18, 18, 19, 16, + // Bottom face + 20, 21, 22, 22, 23, 20 + }; + + GLuint VAO, VBO, EBO; + + // Generate and bind VAO + glGenVertexArrays(1, &VAO); + glBindVertexArray(VAO); + + // Generate and bind VBO + glGenBuffers(1, &VBO); + glBindBuffer(GL_ARRAY_BUFFER, VBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(g_CubeVertices), g_CubeVertices, GL_STATIC_DRAW); + + // Generate and bind EBO + glGenBuffers(1, &EBO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(g_CubeIndices), g_CubeIndices, GL_STATIC_DRAW); + + // Define vertex attributes + // Position attribute (location = 0) + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, + 5 * sizeof(float), (void*)0); + glEnableVertexAttribArray(0); + + // UV attribute (location = 1) + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, + 5 * sizeof(float), (void*)(3 * sizeof(float))); + glEnableVertexAttribArray(1); + + // Unbind VAO (not EBO!) + glBindVertexArray(0); + + // Optionally, unbind VBO and EBO for cleanliness + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + + // Debug: Print VAO ID + printf("[MeshUtils] Initialized CubeVAO with ID: %u\n", VAO); + + return VAO; +} \ No newline at end of file diff --git a/src/TestModel.h b/src/TestModel.h index e69de29..887a049 100644 --- a/src/TestModel.h +++ b/src/TestModel.h @@ -0,0 +1,6 @@ +#pragma once // +#include +#include + + +GLuint CreateCubeVAO(); \ No newline at end of file diff --git a/src/Windows/InspectorWindow.cpp b/src/Windows/InspectorWindow.cpp index 60ba4e9..81c72e5 100644 --- a/src/Windows/InspectorWindow.cpp +++ b/src/Windows/InspectorWindow.cpp @@ -6,7 +6,11 @@ #include -extern std::vector m_GameObjects; +extern std::vector g_GameObjects; +extern GameObject* g_SelectedObject; // Pointer to the currently selected object + + + void InspectorWindow::Show() { @@ -30,10 +34,10 @@ void InspectorWindow::Show() bool transformOpen = ImGui::CollapsingHeader("Transform##Main", ImGuiTreeNodeFlags_DefaultOpen); ImGui::PopStyleColor(); - if (transformOpen) + if (transformOpen && g_SelectedObject) //! Funny: I did not put a null check here and it broke everything. { - Transform* transform = &m_GameObjects[0].transform; + Transform* transform = &g_SelectedObject->transform; if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); diff --git a/src/Windows/RenderWindow.cpp b/src/Windows/RenderWindow.cpp index 188175d..8ab6042 100644 --- a/src/Windows/RenderWindow.cpp +++ b/src/Windows/RenderWindow.cpp @@ -13,7 +13,7 @@ #include "Componenets/Mesh.h" #include "Componenets/Transform.h" -extern std::vector m_GameObjects; +extern std::vector g_GameObjects; #define CAM_FOV 45.0f @@ -209,7 +209,7 @@ void RenderWindow::RenderSceneToFBO() glm::mat4 proj = glm::perspective(glm::radians(CAM_FOV), aspect, CAM_NEAR_PLAIN, CAM_FAR_PLAIN); // Iterate over each GameObject and render it - for (auto& obj : m_GameObjects) + for (auto& obj : g_GameObjects) { // ----------------------------------- // 1) Build MVP from obj.transform diff --git a/src/Windows/SceneWindow.cpp b/src/Windows/SceneWindow.cpp new file mode 100644 index 0000000..4c5cdb6 --- /dev/null +++ b/src/Windows/SceneWindow.cpp @@ -0,0 +1,96 @@ +#include "SceneWindow.h" +#include "imgui.h" +#include "glm/vec3.hpp" + +#include "Engine/AssetManager.h" + +#include "TestModel.h" + +// Globals +extern std::vector g_GameObjects; +extern GameObject* g_SelectedObject; + +extern AssetManager g_AssetManager; + + + +// Helper: Create a default cube GameObject +GameObject CreateDefaultCube() { + GameObject cube; + cube.name = "Cube"; + cube.transform.position = glm::vec3(0.f, 0.f, 0.f); + cube.transform.rotation = glm::vec3(0.f, 0.5f, 0.f); + cube.transform.scale = glm::vec3(1.f, 1.f, 1.f); + cube.mesh.vao = CreateCubeVAO(); // Implement your VAO creation logic + cube.mesh.indexCount = 36; + cube.mesh.textureID = static_cast(reinterpret_cast( + g_AssetManager.loadAsset(AssetType::TEXTURE, "assets/textures/wood.png"))); + return cube; +} + +// Show function implementation +void SceneWindow::Show() { + if (ImGui::Begin("Scene Window")) { + // Add Button + if (ImGui::Button("Add Object")) { + AddGameObject(); + } + + ImGui::Separator(); + + // List GameObjects + int index = 0; + for (auto it = g_GameObjects.begin(); it != g_GameObjects.end(); ++it, ++index) { + GameObject& obj = *it; + std::string uniqueID = obj.name + "##" + std::to_string(index); + + if (ImGui::TreeNode(uniqueID.c_str())) { + // Select GameObject + if (ImGui::Selectable("Select", g_SelectedObject == &obj)) { + g_SelectedObject = &obj; + } + + // Right-click context menu to remove GameObject + if (ImGui::BeginPopupContextItem()) { + if (ImGui::MenuItem("Remove")) { + RemoveGameObject(index); + ImGui::EndPopup(); + break; + } + ImGui::EndPopup(); + } + + ImGui::TreePop(); + } + } + + ImGui::Separator(); + + // Show currently selected object details at the bottom + if (g_SelectedObject) { + ImGui::Text("Selected Object: %s", g_SelectedObject->name.c_str()); + // Optionally add details or editable fields here + } else { + ImGui::Text("No Object Selected"); + } + } + ImGui::End(); +} + +// AddGameObject: Adds a new GameObject +void SceneWindow::AddGameObject() { + g_GameObjects.push_back(CreateDefaultCube()); +} + +// RemoveGameObject: Removes a GameObject by index +void SceneWindow::RemoveGameObject(int index) { + if (index >= 0 && index < static_cast(g_GameObjects.size())) { + g_GameObjects.erase(g_GameObjects.begin() + index); + g_SelectedObject = nullptr; // Clear selection if the removed object was selected + } +} + +// GetSelectedObject function implementation +GameObject* SceneWindow::GetSelectedObject() const { + return g_SelectedObject; +} diff --git a/src/Windows/SceneWindow.h b/src/Windows/SceneWindow.h new file mode 100644 index 0000000..afa37d8 --- /dev/null +++ b/src/Windows/SceneWindow.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include + +#include "Componenets/GameObject.h" + + +// SceneWindow class declaration +class SceneWindow { +public: + void Show(); + GameObject* GetSelectedObject() const; + +private: + void AddGameObject(); // Adds a new game object + void RemoveGameObject(int index); // Removes a game object by index +}; +