Improved openGL and ImGUI implementation

This commit is contained in:
Afonso Clerigo Mendes de Sousa 2026-02-26 19:28:58 +00:00
parent 645faf6546
commit e746781494
2 changed files with 11 additions and 2 deletions

2
.gitignore vendored
View File

@ -101,4 +101,4 @@ _deps
CMakeUserPresets.json CMakeUserPresets.json
build build
.cache .cache
test

View File

@ -9,7 +9,7 @@
const char FRAGMENT_SHADER_SOURCE[] = "./source/shader/fragment.glsl"; const char FRAGMENT_SHADER_SOURCE[] = "./source/shader/fragment.glsl";
const char VERTEX_SHADER_SOURCE[] = "./source/shader/vertex.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_WIDTH = 1920;
const unsigned int SCR_HEIGHT = 1080; const unsigned int SCR_HEIGHT = 1080;
@ -97,12 +97,18 @@ static inline void init_imgui() {
} }
int main() { int main() {
#ifndef NDEBUG
init_imgui(); init_imgui();
#endif
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
// Poll events // Poll events
glfwPollEvents(); glfwPollEvents();
#ifndef NDEBUG
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
// Start ImGui frame // Start ImGui frame
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
@ -112,14 +118,17 @@ int main() {
ImGui::Begin("Debug"); ImGui::Begin("Debug");
ImGui::Text("FPS: %.1f", static_cast<double>(ImGui::GetIO().Framerate)); ImGui::Text("FPS: %.1f", static_cast<double>(ImGui::GetIO().Framerate));
ImGui::End(); ImGui::End();
#endif
// Render // Render
glClearColor(0.03f, 0.03f, 0.03f, 1.0f); glClearColor(0.03f, 0.03f, 0.03f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
#ifndef NDEBUG
// Render ImGui // Render ImGui
ImGui::Render(); ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
#endif
// Swap buffers // Swap buffers
glfwSwapBuffers(window); glfwSwapBuffers(window);