From 5f3f6186cf6dbd4c9b9d3d88d374aa9317d27f5c Mon Sep 17 00:00:00 2001 From: lapinozz Date: Sun, 24 May 2026 02:17:01 -0400 Subject: [PATCH 1/4] Fix GL state saving and application --- imgui-SFML.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/imgui-SFML.cpp b/imgui-SFML.cpp index 216dd40..3738aaa 100644 --- a/imgui-SFML.cpp +++ b/imgui-SFML.cpp @@ -572,7 +572,6 @@ void Render(sf::RenderWindow& window) void Render(sf::RenderTarget& target) { - target.resetGLStates(); target.pushGLStates(); ImGui::Render(); RenderDrawLists(ImGui::GetDrawData()); @@ -923,7 +922,6 @@ void SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height) // viewport apps. glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); glMatrixMode(GL_PROJECTION); - glPushMatrix(); glLoadIdentity(); #ifdef GL_VERSION_ES_CL_1_1 glOrthof(draw_data->DisplayPos.x, @@ -941,7 +939,6 @@ void SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height) +1.0f); #endif glMatrixMode(GL_MODELVIEW); - glPushMatrix(); glLoadIdentity(); } @@ -966,7 +963,31 @@ void RenderDrawLists(ImDrawData* draw_data) draw_data->ScaleClipRects(io.DisplayFramebufferScale); // Backup GL state - // Backup GL state + + GLint last_blend_src; + glGetIntegerv(GL_BLEND_SRC, &last_blend_src); + GLint last_blend_dst; + glGetIntegerv(GL_BLEND_SRC, &last_blend_dst); + + const auto last_blend = glIsEnabled(GL_BLEND); + const auto last_cull_face = glIsEnabled(GL_CULL_FACE); + const auto last_depth_test = glIsEnabled(GL_DEPTH_TEST); + const auto last_stencil_test = glIsEnabled(GL_STENCIL_TEST); + const auto last_lighting = glIsEnabled(GL_LIGHTING); + const auto last_color_material = glIsEnabled(GL_COLOR_MATERIAL); + const auto last_scissor_test = glIsEnabled(GL_SCISSOR_TEST); + const auto last_texture_2d = glIsEnabled(GL_TEXTURE_2D); + + const auto last_vertex_array = glIsEnabled(GL_VERTEX_ARRAY); + const auto last_texture_coord_array = glIsEnabled(GL_TEXTURE_COORD_ARRAY); + const auto last_color_array = glIsEnabled(GL_COLOR_ARRAY); + const auto last_normal_array = glIsEnabled(GL_NORMAL_ARRAY); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + GLint last_texture = 0; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); @@ -1058,9 +1079,47 @@ void RenderDrawLists(ImDrawData* draw_data) } // Restore modified GL state - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); + + const auto setGlState = [](auto state, bool value) + { + if (value) + { + glEnable(state); + } + else + { + glDisable(state); + } + }; + + const auto setGlClientState = [](auto state, bool value) + { + if (value) + { + glEnableClientState(state); + } + else + { + glDisableClientState(state); + } + }; + + setGlState(GL_BLEND, last_blend); + setGlState(GL_CULL_FACE, last_cull_face); + setGlState(GL_DEPTH_TEST, last_depth_test); + setGlState(GL_STENCIL_TEST, last_stencil_test); + setGlState(GL_LIGHTING, last_lighting); + setGlState(GL_COLOR_MATERIAL, last_color_material); + setGlState(GL_SCISSOR_TEST, last_scissor_test); + setGlState(GL_TEXTURE_2D, last_texture_2d); + + setGlClientState(GL_VERTEX_ARRAY, last_vertex_array); + setGlClientState(GL_TEXTURE_COORD_ARRAY, last_texture_coord_array); + setGlClientState(GL_COLOR_ARRAY, last_color_array); + setGlClientState(GL_NORMAL_ARRAY, last_normal_array); + + glBlendFunc(last_blend_src, last_blend_dst); + glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture); glMatrixMode(GL_MODELVIEW); glPopMatrix(); From 7fc035deddd16ea4810103cb4c61f48b454cf110 Mon Sep 17 00:00:00 2001 From: lapinozz Date: Sun, 24 May 2026 02:23:59 -0400 Subject: [PATCH 2/4] Use explicit types --- imgui-SFML.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/imgui-SFML.cpp b/imgui-SFML.cpp index 3738aaa..49f0708 100644 --- a/imgui-SFML.cpp +++ b/imgui-SFML.cpp @@ -969,19 +969,19 @@ void RenderDrawLists(ImDrawData* draw_data) GLint last_blend_dst; glGetIntegerv(GL_BLEND_SRC, &last_blend_dst); - const auto last_blend = glIsEnabled(GL_BLEND); - const auto last_cull_face = glIsEnabled(GL_CULL_FACE); - const auto last_depth_test = glIsEnabled(GL_DEPTH_TEST); - const auto last_stencil_test = glIsEnabled(GL_STENCIL_TEST); - const auto last_lighting = glIsEnabled(GL_LIGHTING); - const auto last_color_material = glIsEnabled(GL_COLOR_MATERIAL); - const auto last_scissor_test = glIsEnabled(GL_SCISSOR_TEST); - const auto last_texture_2d = glIsEnabled(GL_TEXTURE_2D); - - const auto last_vertex_array = glIsEnabled(GL_VERTEX_ARRAY); - const auto last_texture_coord_array = glIsEnabled(GL_TEXTURE_COORD_ARRAY); - const auto last_color_array = glIsEnabled(GL_COLOR_ARRAY); - const auto last_normal_array = glIsEnabled(GL_NORMAL_ARRAY); + const bool last_blend = glIsEnabled(GL_BLEND); + const bool last_cull_face = glIsEnabled(GL_CULL_FACE); + const bool last_depth_test = glIsEnabled(GL_DEPTH_TEST); + const bool last_stencil_test = glIsEnabled(GL_STENCIL_TEST); + const bool last_lighting = glIsEnabled(GL_LIGHTING); + const bool last_color_material = glIsEnabled(GL_COLOR_MATERIAL); + const bool last_scissor_test = glIsEnabled(GL_SCISSOR_TEST); + const bool last_texture_2d = glIsEnabled(GL_TEXTURE_2D); + + const bool last_vertex_array = glIsEnabled(GL_VERTEX_ARRAY); + const bool last_texture_coord_array = glIsEnabled(GL_TEXTURE_COORD_ARRAY); + const bool last_color_array = glIsEnabled(GL_COLOR_ARRAY); + const bool last_normal_array = glIsEnabled(GL_NORMAL_ARRAY); glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -1080,27 +1080,27 @@ void RenderDrawLists(ImDrawData* draw_data) // Restore modified GL state - const auto setGlState = [](auto state, bool value) + const auto setGlState = [](GLint state, bool value) { if (value) { - glEnable(state); + glEnable(static_cast(state)); } else { - glDisable(state); + glDisable(static_cast(state)); } }; - const auto setGlClientState = [](auto state, bool value) + const auto setGlClientState = [](GLint state, bool value) { if (value) { - glEnableClientState(state); + glEnableClientState(static_cast(state)); } else { - glDisableClientState(state); + glDisableClientState(static_cast(state)); } }; From 6cba5213a8b0e48a25e3b34484d8433f311a22a4 Mon Sep 17 00:00:00 2001 From: lapinozz Date: Sun, 24 May 2026 02:27:00 -0400 Subject: [PATCH 3/4] Fix type conversion --- imgui-SFML.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui-SFML.cpp b/imgui-SFML.cpp index 49f0708..115bbfb 100644 --- a/imgui-SFML.cpp +++ b/imgui-SFML.cpp @@ -1118,7 +1118,7 @@ void RenderDrawLists(ImDrawData* draw_data) setGlClientState(GL_COLOR_ARRAY, last_color_array); setGlClientState(GL_NORMAL_ARRAY, last_normal_array); - glBlendFunc(last_blend_src, last_blend_dst); + glBlendFunc(static_cast(last_blend_src), static_cast(last_blend_dst)); glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture); glMatrixMode(GL_MODELVIEW); From b125cebf55340365119e11aba9434fbe6f0f0ad6 Mon Sep 17 00:00:00 2001 From: lapinozz Date: Sun, 24 May 2026 02:32:16 -0400 Subject: [PATCH 4/4] Fix uninitialized variable --- imgui-SFML.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui-SFML.cpp b/imgui-SFML.cpp index 115bbfb..5007741 100644 --- a/imgui-SFML.cpp +++ b/imgui-SFML.cpp @@ -964,9 +964,9 @@ void RenderDrawLists(ImDrawData* draw_data) // Backup GL state - GLint last_blend_src; + GLint last_blend_src{}; glGetIntegerv(GL_BLEND_SRC, &last_blend_src); - GLint last_blend_dst; + GLint last_blend_dst{}; glGetIntegerv(GL_BLEND_SRC, &last_blend_dst); const bool last_blend = glIsEnabled(GL_BLEND);