OpenGL3 backend renders upside down in KDE/Qt environment #8640

Closed
opened 2025-05-16 05:47:40 +00:00 by digitalsignalperson · 0 comments
digitalsignalperson commented 2025-05-16 05:47:40 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version "1.92.0 WIP", Branch: master

Back-ends:

imgui_impl_opengl3.cpp + custom KDE/Qt platform

Compiler, OS:

Linux + GCC

Full config/build information:

No response

Details:

My Issue/Question:

I'm building a plugin for KWin and adding imgui I noticed it renders upside-down. But the existing ifdefs don't apply for me.

  • GL_CLIP_ORIGIN is defined
  • not using GL 4.5
  • not using opengl extensions

I'm not sure how the convention is defined in this KDE/Qt-land, but I just need a define or some way to tell it to do what I want.

I referenced https://github.com/ocornut/imgui/pull/3146 to make this workaround:

diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp
index 7d0b5362..9a2e769c 100644
--- a/backends/imgui_impl_opengl3.cpp
+++ b/backends/imgui_impl_opengl3.cpp
@@ -448,7 +448,9 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
 #endif
 
     // Support for GL 4.5 rarely used glClipControl(GL_UPPER_LEFT)
-#if defined(GL_CLIP_ORIGIN)
+#if defined(FORCE_ORIGIN_UPPER_LEFT)
+    bool clip_origin_lower_left = false;
+#elif defined(GL_CLIP_ORIGIN)
     bool clip_origin_lower_left = true;
     if (bd->HasClipOrigin)
     {
@@ -465,7 +467,7 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
     float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
     float T = draw_data->DisplayPos.y;
     float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
-#if defined(GL_CLIP_ORIGIN)
+#if defined(GL_CLIP_ORIGIN) || defined(FORCE_ORIGIN_UPPER_LEFT)
     if (!clip_origin_lower_left) { float tmp = T; T = B; B = tmp; } // Swap top and bottom if origin is upper left
 #endif
     const float ortho_projection[4][4] =
@@ -624,7 +626,11 @@ void    ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
                     continue;
 
                 // Apply scissor/clipping rectangle (Y is inverted in OpenGL)
-                GL_CALL(glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)));
+                #if defined(FORCE_ORIGIN_UPPER_LEFT)
+                    GL_CALL(glScissor((int)clip_min.x, (int)clip_min.y, (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)));
+                #else
+                    GL_CALL(glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)));
+                #endif
 
                 // Bind texture, Draw
                 GL_CALL(glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()));

Works for me. Is that good enough for a PR or would you rather clean this up another way?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

### Version/Branch of Dear ImGui: Version "1.92.0 WIP", Branch: master ### Back-ends: imgui_impl_opengl3.cpp + custom KDE/Qt platform ### Compiler, OS: Linux + GCC ### Full config/build information: _No response_ ### Details: **My Issue/Question:** I'm building a plugin for KWin and adding imgui I noticed it renders upside-down. But the existing ifdefs don't apply for me. - [x] `GL_CLIP_ORIGIN` is defined - [ ] not using GL 4.5 - [ ] not using opengl extensions I'm not sure how the convention is defined in this KDE/Qt-land, but I just need a define or some way to tell it to do what I want. I referenced https://github.com/ocornut/imgui/pull/3146 to make this workaround: ```diff diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index 7d0b5362..9a2e769c 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -448,7 +448,9 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid #endif // Support for GL 4.5 rarely used glClipControl(GL_UPPER_LEFT) -#if defined(GL_CLIP_ORIGIN) +#if defined(FORCE_ORIGIN_UPPER_LEFT) + bool clip_origin_lower_left = false; +#elif defined(GL_CLIP_ORIGIN) bool clip_origin_lower_left = true; if (bd->HasClipOrigin) { @@ -465,7 +467,7 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; float T = draw_data->DisplayPos.y; float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y; -#if defined(GL_CLIP_ORIGIN) +#if defined(GL_CLIP_ORIGIN) || defined(FORCE_ORIGIN_UPPER_LEFT) if (!clip_origin_lower_left) { float tmp = T; T = B; B = tmp; } // Swap top and bottom if origin is upper left #endif const float ortho_projection[4][4] = @@ -624,7 +626,11 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) continue; // Apply scissor/clipping rectangle (Y is inverted in OpenGL) - GL_CALL(glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y))); + #if defined(FORCE_ORIGIN_UPPER_LEFT) + GL_CALL(glScissor((int)clip_min.x, (int)clip_min.y, (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y))); + #else + GL_CALL(glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y))); + #endif // Bind texture, Draw GL_CALL(glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID())); ``` Works for me. Is that good enough for a PR or would you rather clean this up another way? ### Screenshots/Video: _No response_ ### Minimal, Complete and Verifiable Example code: _No response_
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#8640
No description provided.