From 4bd2d6908ecd1381281535e823ebbe63089d398a Mon Sep 17 00:00:00 2001 From: Nathan Date: Sat, 22 Mar 2025 01:45:25 -0500 Subject: [PATCH] help --- flake.nix | 2 +- .../GUImodules/TestImgui/src/TestImgui.cpp | 44 ++++++++++++------- src/App.cpp | 5 ++- src/GuiModule.h | 5 ++- .../RendererOpenGL/RendererOpenGL.cpp | 6 ++- .../Renderer/RendererOpenGL/RendererOpenGL.h | 2 + utils/Window/WindowGLFW/WindowGLFW.cpp | 7 +-- utils/Window/WindowGLFW/WindowGLFW.h | 2 +- 8 files changed, 46 insertions(+), 27 deletions(-) diff --git a/flake.nix b/flake.nix index 2c5af73..e254d83 100755 --- a/flake.nix +++ b/flake.nix @@ -191,7 +191,7 @@ buildPhase = '' g++ \ - modules/TestImgui/src/*.cpp src/App.cpp \ + modules/GUImodules/TestImgui/src/*.cpp src/App.cpp \ $imgui/backends/imgui_impl_glfw.cpp \ $imgui/backends/imgui_impl_opengl3.cpp \ $imgui/*.cpp \ diff --git a/modules/GUImodules/TestImgui/src/TestImgui.cpp b/modules/GUImodules/TestImgui/src/TestImgui.cpp index 2011512..035be2d 100644 --- a/modules/GUImodules/TestImgui/src/TestImgui.cpp +++ b/modules/GUImodules/TestImgui/src/TestImgui.cpp @@ -7,21 +7,8 @@ #include TestImgui::TestImgui(void* h, Archimedes::App& a) : Archimedes::GuiModule(h, a) { + name = "TestImgui"; - - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); (void)io; - io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls - io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls - - // Setup Dear ImGui style - ImGui::StyleColorsDark(); - //ImGui::StyleColorsLight(); - - // Setup Platform/Renderer backends - ImGui_ImplGlfw_InitForOpenGL(getWindow()->getWindowImpl().getWindow(), true); - ImGui_ImplOpenGL3_Init("#version 130"); } TestImgui::~TestImgui() { @@ -30,7 +17,32 @@ TestImgui::~TestImgui() { ImGui::DestroyContext(); } -void TestImgui::onLoad() {} +void TestImgui::onLoad() { + + createWindow(); + + std::cout << "Check version" << std::endl; + IMGUI_CHECKVERSION(); + std::cout << "CreateContext" << std::endl; + ImGui::CreateContext(); + std::cout << "GetIO" << std::endl; + ImGuiIO& io = ImGui::GetIO(); (void)io; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + + std::cout << "Set Style" << std::endl; + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsLight(); + + std::cout << "ImGui_ImplGlfw_InitForOpenGL" << std::endl; + // Setup Platform/Renderer backends + ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true); + std::cout << "ImGui_ImplOpenGL3_Init" << std::endl; + ImGui_ImplOpenGL3_Init("#version 130"); + + std::cout << "Successful onLoad" << std::endl; +} void TestImgui::run() { @@ -42,7 +54,7 @@ void TestImgui::run() { ImGui::Render(); - getWindow()->getRenderer().addRenderCmd([](){ + window->getRenderer().addRenderCmd([](){ ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); }); diff --git a/src/App.cpp b/src/App.cpp index 7cc6e5e..d2173fb 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -44,9 +44,10 @@ namespace Archimedes { } Module::create_t* create = (Module::create_t*) dlsym(h, "create"); - - if(dlerror()) { + char* err = dlerror(); + if(err) { std::cout << "error finding create function in file: " << lib << std::endl; + std::cout << "dlerror(): " << err << std::endl; } Module* m = create(h, App::Get()); diff --git a/src/GuiModule.h b/src/GuiModule.h index e2b2c5d..123a571 100644 --- a/src/GuiModule.h +++ b/src/GuiModule.h @@ -12,13 +12,14 @@ namespace Archimedes { typedef GuiModule* create_t(void*, App&); GuiModule(void* h, App& a) : Module(h, a) {} - virtual ~GuiModule() {} + virtual ~GuiModule() { if(window) delete window; } virtual void onLoad() = 0; virtual void run() = 0; Window* getWindow() { return window; } + void createWindow() { window = new Window(); } - private: + protected: Window* window; }; } diff --git a/utils/Renderer/RendererOpenGL/RendererOpenGL.cpp b/utils/Renderer/RendererOpenGL/RendererOpenGL.cpp index dc7d050..28a190e 100644 --- a/utils/Renderer/RendererOpenGL/RendererOpenGL.cpp +++ b/utils/Renderer/RendererOpenGL/RendererOpenGL.cpp @@ -1,7 +1,5 @@ #include "RendererOpenGL.h" -#include "pch.hpp" - #define GLEW_STATIC #include @@ -11,6 +9,10 @@ namespace Archimedes { RendererOpenGL::~RendererOpenGL() {} + void RendererOpenGL::init() { + glewInit(); + } + void RendererOpenGL::render(std::list cmdList, int& w, int& h) { glViewport(0, 0, w, h); diff --git a/utils/Renderer/RendererOpenGL/RendererOpenGL.h b/utils/Renderer/RendererOpenGL/RendererOpenGL.h index b3e07e4..0bbf5c8 100644 --- a/utils/Renderer/RendererOpenGL/RendererOpenGL.h +++ b/utils/Renderer/RendererOpenGL/RendererOpenGL.h @@ -13,6 +13,8 @@ namespace Archimedes { RendererOpenGL(); ~RendererOpenGL(); + void init(); + void render(std::list, int&, int&); }; diff --git a/utils/Window/WindowGLFW/WindowGLFW.cpp b/utils/Window/WindowGLFW/WindowGLFW.cpp index 3700fbd..d0b5bc7 100644 --- a/utils/Window/WindowGLFW/WindowGLFW.cpp +++ b/utils/Window/WindowGLFW/WindowGLFW.cpp @@ -6,8 +6,9 @@ namespace Archimedes { WindowGLFW::WindowGLFW() { glfwSetErrorCallback([](int e, const char* m){ - std::cout << "GLFW Error: " << m << std::endl; - }); + std::cout << "GLFW Error: " << m << std::endl; + }); + if(!glfwInit()) { std::cout << "glfwInit failed!\n"; std::abort(); @@ -18,7 +19,7 @@ namespace Archimedes { glfwTerminate(); std::abort(); } - + std::cout << "Window Created!\n"; glfwMakeContextCurrent(w); glfwSwapInterval(1); } diff --git a/utils/Window/WindowGLFW/WindowGLFW.h b/utils/Window/WindowGLFW/WindowGLFW.h index efbd9fe..3df5bd7 100644 --- a/utils/Window/WindowGLFW/WindowGLFW.h +++ b/utils/Window/WindowGLFW/WindowGLFW.h @@ -18,7 +18,7 @@ namespace Archimedes { void getSize(int&, int&); - auto getWindow() { return w; } + GLFWwindow* getWindow() { return w; } private: GLFWwindow* w;