diff --git a/modules/ImguiModule/src/ImguiModule.cpp b/modules/ImguiModule/src/ImguiModule.cpp index 137a342..fa65592 100644 --- a/modules/ImguiModule/src/ImguiModule.cpp +++ b/modules/ImguiModule/src/ImguiModule.cpp @@ -1,6 +1,5 @@ #include "ImguiModule.h" -#include "imgui.h" #include "backends/imgui_impl_glfw.h" #include "backends/imgui_impl_opengl3.h" @@ -27,7 +26,7 @@ void ImguiModule::onLoad() { } IMGUI_CHECKVERSION(); - ImGui::CreateContext(); + context = ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls diff --git a/modules/ImguiModule/src/ImguiModule.h b/modules/ImguiModule/src/ImguiModule.h index 204c19e..757ba88 100644 --- a/modules/ImguiModule/src/ImguiModule.h +++ b/modules/ImguiModule/src/ImguiModule.h @@ -6,6 +6,8 @@ #include "utils/Window/Window.h" +#include "imgui.h" + class ImguiModule : public Archimedes::GuiModule { public: @@ -19,9 +21,11 @@ class ImguiModule : public Archimedes::GuiModule { void run(); + ImGuiContext* getContext() { return context; } private: - + + ImGuiContext* context; }; #ifdef IMGUIMODULE_DYNAMIC diff --git a/modules/examples/GuiModules/TestImgui/src/TestImgui.cpp b/modules/examples/GuiModules/TestImgui/src/TestImgui.cpp index 657ea58..a15c38d 100644 --- a/modules/examples/GuiModules/TestImgui/src/TestImgui.cpp +++ b/modules/examples/GuiModules/TestImgui/src/TestImgui.cpp @@ -28,6 +28,16 @@ void TestImgui::onLoad() { std::cout << "No WindowModule for TestImgui!\n"; std::abort(); } + + ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"]; + + if(!im) { + std::cout << "No ImguiModule for TestImgui!\n"; + std::abort(); + } + + ImGui::SetCurrentContext(im->getContext()); + } void TestImgui::run() { @@ -41,7 +51,7 @@ void TestImgui::run() { static float f = 0.0f; static int counter = 0; - ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. + ImGui::Begin("TestImgui Module"); // Create a window called "Hello, world!" and append into it. ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)