From e7467814944e9a533c5c0e3ce5620195341c3864 Mon Sep 17 00:00:00 2001 From: AfonsoCMSousa Date: Thu, 26 Feb 2026 19:28:58 +0000 Subject: [PATCH] Improved openGL and ImGUI implementation --- .gitignore | 2 +- source/main.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2366730..bc08da3 100644 --- a/.gitignore +++ b/.gitignore @@ -101,4 +101,4 @@ _deps CMakeUserPresets.json build .cache - +test diff --git a/source/main.cpp b/source/main.cpp index 61fbc71..5eb2251 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -9,7 +9,7 @@ const char FRAGMENT_SHADER_SOURCE[] = "./source/shader/fragment.glsl"; const char VERTEX_SHADER_SOURCE[] = "./source/shader/vertex.glsl"; -const char PROGRAM_NAME[] = "ImGui OpenGL Example"; +const char PROGRAM_NAME[] = "OpenGL Template"; const unsigned int SCR_WIDTH = 1920; const unsigned int SCR_HEIGHT = 1080; @@ -97,12 +97,18 @@ static inline void init_imgui() { } int main() { +#ifndef NDEBUG init_imgui(); +#endif while (!glfwWindowShouldClose(window)) { // Poll events glfwPollEvents(); +#ifndef NDEBUG + if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { + glfwSetWindowShouldClose(window, true); + } // Start ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); @@ -112,14 +118,17 @@ int main() { ImGui::Begin("Debug"); ImGui::Text("FPS: %.1f", static_cast(ImGui::GetIO().Framerate)); ImGui::End(); +#endif // Render glClearColor(0.03f, 0.03f, 0.03f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); +#ifndef NDEBUG // Render ImGui ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); +#endif // Swap buffers glfwSwapBuffers(window);