Skip to content

Commit 4f3fc42

Browse files
committed
Make ImGui usable in GL3 mode, fix demo window offset
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 22a91fb commit 4f3fc42

3 files changed

Lines changed: 49 additions & 6 deletions

File tree

‎opengl/DearImGui/dpf-changes.diff‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,44 @@ index 2a255be..3d30626 100644
2222
}
2323

2424
// OpenGL2 Render function.
25+
diff --git a/opengl/DearImGui/imgui_impl_opengl3.cpp b/opengl/DearImGui/imgui_impl_opengl3.cpp
26+
index 7d0b536..c559ba7 100644
27+
--- a/opengl/DearImGui/imgui_impl_opengl3.cpp
28+
+++ b/opengl/DearImGui/imgui_impl_opengl3.cpp
29+
@@ -460,11 +460,19 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
30+
31+
// Setup viewport, orthographic projection matrix
32+
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
33+
+#ifdef IMGUI_DPF_BACKEND
34+
+ GL_CALL(glViewport(-draw_data->DisplayPos.x, draw_data->DisplayPos.y, (GLsizei)fb_width, (GLsizei)fb_height));
35+
+ float L = 0;
36+
+ float R = draw_data->DisplaySize.x;
37+
+ float T = 0;
38+
+ float B = draw_data->DisplaySize.y;
39+
+#else
40+
GL_CALL(glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height));
41+
float L = draw_data->DisplayPos.x;
42+
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
43+
float T = draw_data->DisplayPos.y;
44+
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
45+
+#endif
46+
#if defined(GL_CLIP_ORIGIN)
47+
if (!clip_origin_lower_left) { float tmp = T; T = B; B = tmp; } // Swap top and bottom if origin is upper left
48+
#endif
49+
diff --git a/opengl/DearImGui/imgui_demo.cpp b/opengl/DearImGui/imgui_demo.cpp
50+
index 10fa434..128cf00 100644
51+
--- a/opengl/DearImGui/imgui_demo.cpp
52+
+++ b/opengl/DearImGui/imgui_demo.cpp
53+
@@ -395,12 +395,6 @@ void ImGui::ShowDemoWindow(bool* p_open)
54+
if (unsaved_document) window_flags |= ImGuiWindowFlags_UnsavedDocument;
55+
if (no_close) p_open = NULL; // Don't pass our bool* to Begin
56+
57+
- // We specify a default position/size in case there's no data in the .ini file.
58+
- // We only do it to make the demo applications a little more welcoming, but typically this isn't required.
59+
- const ImGuiViewport* main_viewport = ImGui::GetMainViewport();
60+
- ImGui::SetNextWindowPos(ImVec2(main_viewport->WorkPos.x + 650, main_viewport->WorkPos.y + 20), ImGuiCond_FirstUseEver);
61+
- ImGui::SetNextWindowSize(ImVec2(550, 680), ImGuiCond_FirstUseEver);
62+
-
63+
// Main body of the Demo window starts here.
64+
if (!ImGui::Begin("Dear ImGui Demo", p_open, window_flags))
65+
{

‎opengl/DearImGui/imgui_demo.cpp‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,6 @@ void ImGui::ShowDemoWindow(bool* p_open)
395395
if (unsaved_document) window_flags |= ImGuiWindowFlags_UnsavedDocument;
396396
if (no_close) p_open = NULL; // Don't pass our bool* to Begin
397397

398-
// We specify a default position/size in case there's no data in the .ini file.
399-
// We only do it to make the demo applications a little more welcoming, but typically this isn't required.
400-
const ImGuiViewport* main_viewport = ImGui::GetMainViewport();
401-
ImGui::SetNextWindowPos(ImVec2(main_viewport->WorkPos.x + 650, main_viewport->WorkPos.y + 20), ImGuiCond_FirstUseEver);
402-
ImGui::SetNextWindowSize(ImVec2(550, 680), ImGuiCond_FirstUseEver);
403-
404398
// Main body of the Demo window starts here.
405399
if (!ImGui::Begin("Dear ImGui Demo", p_open, window_flags))
406400
{

‎opengl/DearImGui/imgui_impl_opengl3.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,19 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
460460

461461
// Setup viewport, orthographic projection matrix
462462
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
463+
#ifdef IMGUI_DPF_BACKEND
464+
GL_CALL(glViewport(-draw_data->DisplayPos.x, draw_data->DisplayPos.y, (GLsizei)fb_width, (GLsizei)fb_height));
465+
float L = 0;
466+
float R = draw_data->DisplaySize.x;
467+
float T = 0;
468+
float B = draw_data->DisplaySize.y;
469+
#else
463470
GL_CALL(glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height));
464471
float L = draw_data->DisplayPos.x;
465472
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
466473
float T = draw_data->DisplayPos.y;
467474
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
475+
#endif
468476
#if defined(GL_CLIP_ORIGIN)
469477
if (!clip_origin_lower_left) { float tmp = T; T = B; B = tmp; } // Swap top and bottom if origin is upper left
470478
#endif

0 commit comments

Comments
 (0)