From a53db1e7b4c1b26b42a44e5d75a4e438e6f917a0 Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Mon, 16 Aug 2021 21:37:09 +0200 Subject: [PATCH] progress... --- data/lights.json | 30 -------------------------- data/{models.json => scene.json} | 4 ++++ src/Controller.cpp | 30 ++++++++++++++------------ src/Controller.h | 2 +- src/Entity.cpp | 36 ++++++++++++++++++++++++++++++++ src/Entity.h | 25 +++++++++++++++------- src/JsonParser.cpp | 30 +++++++++++++++++++++----- src/Light.cpp | 8 +++---- src/Light.h | 23 ++++++++++++-------- src/Scene.cpp | 23 +++++++++++++++----- src/imgui/EntityWindow.cpp | 31 +++++++++++++++++++++++++++ src/imgui/EntityWindow.h | 24 +++++++++++++++++++++ src/imgui/GeneralInfoWindow.cpp | 7 ++----- src/imgui/GeneralInfoWindow.h | 2 +- src/imgui/Handler.cpp | 7 +++++++ src/imgui/Window.cpp | 11 +++------- src/imgui/Window.h | 6 +++++- 17 files changed, 210 insertions(+), 89 deletions(-) delete mode 100644 data/lights.json rename data/{models.json => scene.json} (93%) diff --git a/data/lights.json b/data/lights.json deleted file mode 100644 index f3d9d46..0000000 --- a/data/lights.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "directionalLight": { - "intensity": 0.25, - "direction": [ - -0.2, - -1.0, - -0.3 - ], - "color": [ - 1.0, - 1.0, - 1.0 - ] - }, - "pointLights": [ - { - "intensity": 7.5, - "position": [ - 0.0, - 1.0, - 0.0 - ], - "color": [ - 1.0, - 1.0, - 1.0 - ] - } - ] -} \ No newline at end of file diff --git a/data/models.json b/data/scene.json similarity index 93% rename from data/models.json rename to data/scene.json index 63073c3..c79c57d 100644 --- a/data/models.json +++ b/data/scene.json @@ -40,6 +40,7 @@ }, { "unique_name": "container", + "parent": "backpack", "model": "container", "shaderProgram": "defaultProgram", "position": [ @@ -65,6 +66,7 @@ } ], "directionalLight": { + "unique_name": "directionalLight", "intensity": 0.25, "direction": [ -0.2, @@ -79,6 +81,8 @@ }, "pointLights": [ { + "unique_name": "pointLight0", + "parent": "light", "intensity": 7.5, "position": [ 0.0, diff --git a/src/Controller.cpp b/src/Controller.cpp index d24c0c1..bc2d7fe 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -9,6 +9,7 @@ #include #ifdef _DEBUG +#include "imgui/EntityWindow.h" #include "imgui/GeneralInfoWindow.h" #include "imgui/Handler.h" #endif @@ -57,7 +58,7 @@ Controller::Controller() : m_gameWindow(std::unique_ptr(new Window)) // Show main menu when loading is finished... m_menu->showScreenByName("mainMenuScreen"); - m_world = new Scene(m_shaderPrograms); + m_scene = new Scene(m_shaderPrograms); #ifdef _DEBUG m_imguiHandler = std::unique_ptr(new Imgui::Handler(m_gameWindow->getGLFWwindow())); @@ -70,7 +71,7 @@ Controller::~Controller() delete program; } - delete m_world; + delete m_scene; delete m_camera; delete m_menu; delete m_postProcessFrameBuffer; @@ -87,7 +88,7 @@ void Controller::run() { updateExposure(getShaderProgramByName("postProcessingProgram")); - ModelEntity *lightSource = m_world->getEntityByName("light"); + ModelEntity *lightSource = m_scene->getEntityByName("light"); lightSource->setScale(0.1f); lightSource->setRotation(glm::vec3(0.f)); lightSource->setPosition(glm::vec3(-2.f, 1.5f, 2.f)); @@ -99,10 +100,13 @@ void Controller::run() glm::vec3 lightColor = glm::vec3(1.f); float intensity = 7.5f; #ifdef _DEBUG - std::shared_ptr imguiWindow = std::make_shared( - this, m_world, getShaderProgramByName("postProcessingProgram"), &rotateEntity, &drawShadows, &rotateLightSource, + std::shared_ptr generalWindow = std::make_shared( + this, m_scene, getShaderProgramByName("postProcessingProgram"), &rotateEntity, &drawShadows, &rotateLightSource, &lightColor, &m_exposure, &intensity); - m_imguiHandler->addImguiWindow(imguiWindow); + m_imguiHandler->addImguiWindow(generalWindow); + + std::shared_ptr entityWindow = std::make_shared(m_scene->getEntities()); + m_imguiHandler->addImguiWindow(entityWindow); #endif // This is the game loop @@ -116,14 +120,14 @@ void Controller::run() if (rotateLightSource) { float radius = 4.0; glm::vec3 newPos = glm::vec3(-cos(glfwGetTime() * 0.5), 0.5f, sin(glfwGetTime() * 0.5)) * radius; - m_world->getEntityByName("light")->setPosition(newPos); + m_scene->getEntityByName("light")->setPosition(newPos); } if (rotateEntity) { - m_world->getEntityById(0)->rotate(glm::vec3(0.0f, 1.0f, 0.0f), -0.2f * m_deltaTime); + m_scene->getEntityById(0)->rotate(glm::vec3(0.0f, 1.0f, 0.0f), -0.2f * m_deltaTime); } - m_world->updatePointLight(0, true, m_world->getEntityByName("light")->getPosition(), lightColor, intensity); - m_world->updateDirectionalLight(true, m_world->getDirectionalLight()->getDirection(), lightColor); + m_scene->updatePointLight(0, true, m_scene->getEntityByName("light")->getPosition(), lightColor, intensity); + m_scene->updateDirectionalLight(true, m_scene->getDirectionalLight()->getDirection(), lightColor); getShaderProgramByName("lightProgram")->bind(); getShaderProgramByName("lightProgram")->setUniform("v_lightColor", lightColor * 100.0f); getShaderProgramByName("lightProgram")->unbind(); @@ -137,7 +141,7 @@ void Controller::run() getShaderProgramByName("defaultProgram")->unbind(); if (drawShadows || firstRun) { firstRun = false; - m_world->calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"), + m_scene->calculateShadows(getShaderProgramByName("directionalShadowDepthProgram"), getShaderProgramByName("pointShadowDepthProgram")); } @@ -153,8 +157,8 @@ void Controller::run() m_camera->lookForward(); m_camera->updateVPM(); - m_world->getSkybox()->draw(m_camera->getView(), m_camera->getProj()); - m_world->draw(m_camera->getViewProj(), m_camera->getPosition()); + m_scene->getSkybox()->draw(m_camera->getView(), m_camera->getProj()); + m_scene->draw(m_camera->getViewProj(), m_camera->getPosition()); m_postProcessFrameBuffer->unbind(); m_postProcessFrameBuffer->drawOnEntireScreen(); diff --git a/src/Controller.h b/src/Controller.h index 30c9b05..1a9942d 100644 --- a/src/Controller.h +++ b/src/Controller.h @@ -45,7 +45,7 @@ private: std::unique_ptr m_gameWindow; EventHandler *m_gameEventHandler; - Scene *m_world; + Scene *m_scene; Camera *m_camera; Menu *m_menu; diff --git a/src/Entity.cpp b/src/Entity.cpp index 000558e..3c93750 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -25,39 +25,75 @@ const std::string &Entity::getUniqueName() const return m_uniqueName; } +void Entity::setParent(Entity *parent) +{ + m_parent = parent; +} + +void Entity::addChild(Entity *child) +{ + m_children.push_back(child); +} + void Entity::translate(glm::vec3 vector) { + for (auto &child : m_children) { + child->translate(vector); + } + m_position += vector; + updateModelMatrix(); } void Entity::rotate(glm::vec3 axis, float radians) { + for (auto &child : m_children) { + child->rotate(axis, radians); + } + glm::quat rotation = glm::angleAxis(radians, axis); m_quaternion = rotation * m_quaternion; + updateModelMatrix(); } void Entity::setPosition(glm::vec3 position) { + for (auto &child : m_children) { + child->setPosition(child->getPosition() - m_position + position); + } + m_position = position; updateModelMatrix(); } void Entity::setRotation(glm::vec3 eulerAngles) { + for (auto &child : m_children) { + child->setRotation(eulerAngles); + } + m_quaternion = glm::quat(eulerAngles); updateModelMatrix(); } void Entity::setRotation(glm::vec3 axis, float radians) { + for (auto &child : m_children) { + child->setRotation(axis, radians); + } + m_quaternion = glm::angleAxis(radians, axis); updateModelMatrix(); } void Entity::setScale(float scale) { + for (auto &child : m_children) { + child->setScale(scale); + } + m_scale = scale; updateModelMatrix(); } diff --git a/src/Entity.h b/src/Entity.h index b310a68..19f5729 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -15,12 +15,14 @@ class Entity public: struct Prototype { - Prototype(const std::string &name, glm::vec3 position, glm::vec3 rotation, float scale) - : name(name), position(position), rotation(rotation), scale(scale) + Prototype(const std::string &name, const std::string &parent, glm::vec3 position, glm::vec3 rotation, + float scale) + : name(name), parent(parent), position(position), rotation(rotation), scale(scale) {} virtual ~Prototype() = default; std::string name; + std::string parent; glm::vec3 position; glm::vec3 rotation; float scale; @@ -32,6 +34,13 @@ public: uint32_t getId() const; const std::string &getUniqueName() const; + void setParent(Entity *parent); + void addChild(Entity *child); + const std::vector &getChildren() const + { + return m_children; + } + void translate(glm::vec3 vector); void rotate(glm::vec3 axis, float radians); @@ -50,8 +59,10 @@ protected: static uint32_t s_idCounter; // TODO - std::weak_ptr m_parent; - std::vector> m_children; + // std::weak_ptr m_parent; + Entity *m_parent = nullptr; + // std::vector> m_children; + std::vector m_children; std::string m_uniqueName; @@ -67,9 +78,9 @@ class ModelEntity : public Entity public: struct Prototype : public Entity::Prototype { - Prototype(const std::string &name, glm::vec3 position, glm::vec3 rotation, float scale, - const std::string &modelName, const std::string &shaderProgramName) - : Entity::Prototype(name, position, rotation, scale), modelName(modelName), + Prototype(const std::string &name, const std::string &parent, glm::vec3 position, glm::vec3 rotation, + float scale, const std::string &modelName, const std::string &shaderProgramName) + : Entity::Prototype(name, parent, position, rotation, scale), modelName(modelName), shaderProgramName(shaderProgramName) {} std::string modelName; diff --git a/src/JsonParser.cpp b/src/JsonParser.cpp index 9f84e2a..ebecd17 100644 --- a/src/JsonParser.cpp +++ b/src/JsonParser.cpp @@ -52,11 +52,13 @@ std::vector JsonParser::getEntityPrototypes() const std::string entityModel = entitiesJson[index]["model"].asString(); std::string entityShaderProgram = entitiesJson[index]["shaderProgram"].asString(); glm::vec3 entitiyPosition = {}, entityRotation = {}; + std::string entityParent = ""; float entityScale = 1.0f; const Json::Value positionJson = entitiesJson[index]["position"]; const Json::Value rotationJson = entitiesJson[index]["rotation"]; const Json::Value scaleJson = entitiesJson[index]["scale"]; + const Json::Value parentJson = entitiesJson[index]["parent"]; if (!positionJson.empty()) { entitiyPosition.x = positionJson[0].asFloat(); entitiyPosition.y = positionJson[1].asFloat(); @@ -70,9 +72,11 @@ std::vector JsonParser::getEntityPrototypes() const if (!scaleJson.empty()) { entityScale = scaleJson.asFloat(); } + if (!parentJson.empty()) + entityParent = parentJson.asString(); - ModelEntity::Prototype prototype(entityName, entitiyPosition, entityRotation, entityScale, entityModel, - entityShaderProgram); + ModelEntity::Prototype prototype(entityName, entityParent, entitiyPosition, entityRotation, entityScale, + entityModel, entityShaderProgram); entityPrototypes.push_back(prototype); } @@ -107,6 +111,7 @@ std::vector> JsonParser::getLightPrototypes() glm::vec3 direction = {1.0f, 0.0f, 0.0f}; glm::vec3 position = {}; glm::vec3 color = {1.0f, 1.0f, 1.0f}; + std::string unique_name = ""; float intensity = 10.0f; const Json::Value directionalLightsJson = m_root["directionalLight"]; @@ -114,6 +119,7 @@ std::vector> JsonParser::getLightPrototypes() const Json::Value directionJson = directionalLightsJson["direction"]; Json::Value colorJson = directionalLightsJson["color"]; Json::Value intensityJson = directionalLightsJson["intensity"]; + Json::Value nameJson = directionalLightsJson["unique_name"]; if (!intensityJson.empty()) { intensity = intensityJson.asFloat(); @@ -128,8 +134,11 @@ std::vector> JsonParser::getLightPrototypes() color.y = colorJson[1].asFloat(); color.z = colorJson[2].asFloat(); } + if (!nameJson.empty()) + unique_name = nameJson.asString(); - auto prototype = std::unique_ptr(new DirectionalLight::Prototype{direction, color, intensity}); + auto prototype = + std::unique_ptr(new DirectionalLight::Prototype{unique_name, direction, color, intensity}); prototypes.push_back(std::move(prototype)); @@ -141,6 +150,9 @@ std::vector> JsonParser::getLightPrototypes() const Json::Value positionJson = pointLightsJson[index]["position"]; colorJson = pointLightsJson[index]["color"]; intensityJson = pointLightsJson[index]["intensity"]; + nameJson = pointLightsJson[index]["unique_name"]; + const Json::Value parentJson = pointLightsJson[index]["parent"]; + std::string parent = ""; if (!intensityJson.empty()) { intensity = intensityJson.asFloat(); @@ -156,7 +168,15 @@ std::vector> JsonParser::getLightPrototypes() color.z = colorJson[2].asFloat(); } - auto prototype = std::unique_ptr(new PointLight::Prototype{position, color, intensity}); + unique_name = ""; + if (!nameJson.empty()) + unique_name = nameJson.asString(); + + if (!parentJson.empty()) + parent = parentJson.asString(); + + auto prototype = std::unique_ptr( + new PointLight::Prototype{unique_name, parent, position, color, intensity}); prototypes.push_back(std::move(prototype)); } @@ -167,7 +187,7 @@ std::vector> JsonParser::getLightPrototypes() const glm::vec3 default_color(1.0f); const float default_intensity = 10.0f; auto prototype = std::unique_ptr( - new PointLight::Prototype{default_position, default_color, default_intensity}); + new PointLight::Prototype{"_fallbackLight", "", default_position, default_color, default_intensity}); prototypes.push_back(std::move(prototype)); } diff --git a/src/Light.cpp b/src/Light.cpp index 91d46ea..2dce9d4 100644 --- a/src/Light.cpp +++ b/src/Light.cpp @@ -5,8 +5,8 @@ uint32_t Light::s_idCounter = 0; -Light::Light(glm::vec3 color, float intensity, ShaderProgram *shaderProgram) - : Entity("Light"), m_shaderProgram(shaderProgram), m_intensity(intensity) +Light::Light(const std::string &name, glm::vec3 color, float intensity, ShaderProgram *shaderProgram) + : Entity(name), m_shaderProgram(shaderProgram), m_intensity(intensity) { m_id = s_idCounter++; m_lightColor = color * intensity; @@ -44,7 +44,7 @@ void Light::setActive(bool active) } PointLight::PointLight(Prototype prototype, ShaderProgram *shaderProgram) - : Light(prototype.color, prototype.intensity, shaderProgram), m_position(prototype.position) + : Light(prototype.name, prototype.color, prototype.intensity, shaderProgram), m_position(prototype.position) {} void PointLight::update() @@ -77,7 +77,7 @@ void PointLight::setPosition(glm::vec3 position) } DirectionalLight::DirectionalLight(Prototype prototype, ShaderProgram *shaderProgram) - : Light(prototype.color, prototype.intensity, shaderProgram), m_direction(prototype.direction) + : Light(prototype.name, prototype.color, prototype.intensity, shaderProgram), m_direction(prototype.direction) {} void DirectionalLight::update() diff --git a/src/Light.h b/src/Light.h index 39c30bb..dd9aea7 100644 --- a/src/Light.h +++ b/src/Light.h @@ -14,10 +14,18 @@ class Light : public Entity public: struct Prototype { + Prototype(const std::string &name, const std::string &parent, glm::vec3 color, float intensity) + : name(name), parent(parent), color(color), intensity(intensity) + {} virtual ~Prototype() = default; + + std::string name; + std::string parent; + glm::vec3 color; + float intensity; }; - Light(glm::vec3 color, float intensity, ShaderProgram *shaderProgram); + Light(const std::string &name, glm::vec3 color, float intensity, ShaderProgram *shaderProgram); virtual ~Light() = 0; virtual void update() = 0; @@ -49,12 +57,11 @@ class PointLight : public Light public: struct Prototype : public Light::Prototype { - Prototype(glm::vec3 position, glm::vec3 color, float intensity) - : position(position), color(color), intensity(intensity) + Prototype(const std::string &name, const std::string &parent, glm::vec3 position, glm::vec3 color, + float intensity) + : Light::Prototype(name, parent, color, intensity), position(position) {} glm::vec3 position; - glm::vec3 color; - float intensity; }; PointLight(Prototype prototype, ShaderProgram *shaderProgram); @@ -76,12 +83,10 @@ class DirectionalLight : public Light public: struct Prototype : public Light::Prototype { - Prototype(glm::vec3 direction, glm::vec3 color, float intensity) - : direction(direction), color(color), intensity(intensity) + Prototype(const std::string &name, glm::vec3 direction, glm::vec3 color, float intensity) + : Light::Prototype(name, "", color, intensity), direction(direction) {} glm::vec3 direction; - glm::vec3 color; - float intensity; }; DirectionalLight(Prototype prototype, ShaderProgram *shaderProgram); diff --git a/src/Scene.cpp b/src/Scene.cpp index 512a570..cdca07c 100644 --- a/src/Scene.cpp +++ b/src/Scene.cpp @@ -28,7 +28,7 @@ Scene::Scene(std::vector shaderPrograms) m_shaderProgram->setUniform("u_material.shininess", 100.0f); m_shaderProgram->unbind(); - JsonParser modelParser("data/models.json"); + JsonParser modelParser("data/scene.json"); std::vector modelPrototypes = modelParser.getModelPrototypes(); @@ -66,7 +66,6 @@ Scene::Scene(std::vector shaderPrograms) std::vector entityPrototypes = modelParser.getEntityPrototypes(); - std::vector entities; { for (auto &prototype : entityPrototypes) { // Get model @@ -92,12 +91,19 @@ Scene::Scene(std::vector shaderPrograms) std::cout << "Loaded Entity \"" << prototype.name << "\" with model \"" << prototype.modelName << "\"" << std::endl; - entities.push_back(currentEntity); + if (!prototype.parent.empty()) { + Entity *parent = getEntityByName(prototype.parent); + if (parent) { + parent->addChild(currentEntity); + currentEntity->setParent(parent); + } + } + + m_entities.push_back(currentEntity); } } - m_entities = entities; - JsonParser lightParser("data/lights.json"); + JsonParser lightParser("data/scene.json"); auto lightPrototypes = lightParser.getLightPrototypes(); std::vector lights; @@ -111,6 +117,13 @@ Scene::Scene(std::vector shaderPrograms) auto pointPrototype = dynamic_cast(prototype.get()); if (pointPrototype) { currentLight = new PointLight(*pointPrototype, m_shaderProgram); + if (!pointPrototype->parent.empty()) { + Entity *parent = getEntityByName(pointPrototype->parent); + if (parent) { + parent->addChild(currentLight); + currentLight->setParent(parent); + } + } } lights.push_back(currentLight); } diff --git a/src/imgui/EntityWindow.cpp b/src/imgui/EntityWindow.cpp index e69de29..6a0b32b 100644 --- a/src/imgui/EntityWindow.cpp +++ b/src/imgui/EntityWindow.cpp @@ -0,0 +1,31 @@ +#include "EntityWindow.h" +#include "../Entity.h" + +#include + +Imgui::EntityWindow::EntityWindow(const std::vector &entities) : Window("Entities"), m_entites(entities) +{} + +void Imgui::EntityWindow::addWidgets() +{ + ImGui::Text("Treelist"); + + for (const auto &entity : m_entites) { + // addChildWidget(*entity); + } +} + +void Imgui::EntityWindow::addChildWidget(const ModelEntity &entity) +{ + if (entity.getChildren().empty()) { + ImGui::Text(entity.getUniqueName().c_str()); + } else { + if (ImGui::TreeNode(entity.getUniqueName().c_str())) { + for (const auto &child : entity.getChildren()) { + addChildWidget(*(const ModelEntity *)child); + } + ImGui::TreePop(); + ImGui::Separator(); + } + } +} \ No newline at end of file diff --git a/src/imgui/EntityWindow.h b/src/imgui/EntityWindow.h index e69de29..1a50606 100644 --- a/src/imgui/EntityWindow.h +++ b/src/imgui/EntityWindow.h @@ -0,0 +1,24 @@ +#pragma once + +#include "Window.h" + +#include + +class ModelEntity; + +namespace Imgui { + +class EntityWindow : public Window +{ +public: + EntityWindow(const std::vector &entities); + +private: + void addWidgets() override; + + static void addChildWidget(const ModelEntity &entity); + + const std::vector &m_entites; +}; + +} // namespace Imgui \ No newline at end of file diff --git a/src/imgui/GeneralInfoWindow.cpp b/src/imgui/GeneralInfoWindow.cpp index 2b9af19..cb1d530 100644 --- a/src/imgui/GeneralInfoWindow.cpp +++ b/src/imgui/GeneralInfoWindow.cpp @@ -10,14 +10,13 @@ Imgui::GeneralInfoWindow::GeneralInfoWindow(Controller *controller, Scene *world, ShaderProgram *postProcessingProgram, bool *rotateEntity, bool *drawShadows, bool *rotateLightSource, glm::vec3 *lightColor, float *exposure, float *intensity) - : m_controller(controller), m_world(world), m_postProcessingProgram(postProcessingProgram), + : Window("Debug Utils"), m_controller(controller), m_scene(world), m_postProcessingProgram(postProcessingProgram), m_rotateEntity(rotateEntity), m_drawShadows(drawShadows), m_rotateLightSource(rotateLightSource), m_lightColor(lightColor), m_exposure(exposure), m_intensity(intensity) {} void Imgui::GeneralInfoWindow::addWidgets() { - ImGui::Begin("Debug Utils"); ImGui::Text("Object"); ImGui::SliderFloat("Rotation", &m_rotation, 0, 2 * M_PI); @@ -26,7 +25,7 @@ void Imgui::GeneralInfoWindow::addWidgets() ImGui::Checkbox("Rotate Object", m_rotateEntity); - ModelEntity *mainObject = m_world->getEntityById(0); + ModelEntity *mainObject = m_scene->getEntityById(0); mainObject->setPosition(glm::vec3(m_translation[0], m_translation[1], m_translation[2])); if (!*m_rotateEntity) { mainObject->setRotation(glm::vec3(0.f, 1.0f, 0.f), m_rotation); @@ -53,6 +52,4 @@ void Imgui::GeneralInfoWindow::addWidgets() ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0 / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); - - ImGui::End(); } \ No newline at end of file diff --git a/src/imgui/GeneralInfoWindow.h b/src/imgui/GeneralInfoWindow.h index ca23519..08c2882 100644 --- a/src/imgui/GeneralInfoWindow.h +++ b/src/imgui/GeneralInfoWindow.h @@ -21,7 +21,7 @@ private: void addWidgets() override; Controller *m_controller; - Scene *m_world; + Scene *m_scene; ShaderProgram *m_postProcessingProgram; bool *m_rotateEntity; diff --git a/src/imgui/Handler.cpp b/src/imgui/Handler.cpp index 64c8704..dd1af5d 100644 --- a/src/imgui/Handler.cpp +++ b/src/imgui/Handler.cpp @@ -38,6 +38,13 @@ void Imgui::Handler::addImguiWindow(std::shared_ptr window) void Imgui::Handler::renderWindows() { + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + for (auto window : m_windows) window->render(); + + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } \ No newline at end of file diff --git a/src/imgui/Window.cpp b/src/imgui/Window.cpp index 2ebc566..b99e199 100644 --- a/src/imgui/Window.cpp +++ b/src/imgui/Window.cpp @@ -4,17 +4,12 @@ #include #include -Imgui::Window::Window() +Imgui::Window::Window(const std::string &title) : m_title(title) {} void Imgui::Window::render() { - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); - + ImGui::Begin(m_title.c_str()); addWidgets(); - - ImGui::Render(); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + ImGui::End(); } \ No newline at end of file diff --git a/src/imgui/Window.h b/src/imgui/Window.h index c8d1188..97c1a58 100644 --- a/src/imgui/Window.h +++ b/src/imgui/Window.h @@ -1,15 +1,19 @@ #pragma once +#include + namespace Imgui { class Window { public: - Window(); + Window(const std::string &title); void render(); protected: virtual void addWidgets() = 0; + + std::string m_title; }; } // namespace Imgui