From a9b0abe493d4209660e68d0a1850b413c18fd941 Mon Sep 17 00:00:00 2001 From: Nick Gravelyn Date: Wed, 20 Jan 2016 06:06:31 -0800 Subject: [PATCH 1/4] Automatically updating DisplayFrameBufferScale by reading the OpenGL drawable size and comparing with the window size. This fixed dear imgui which was rendering only to 1/4 of my window. --- examples/sdl_opengl_example/imgui_impl_sdl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/sdl_opengl_example/imgui_impl_sdl.cpp b/examples/sdl_opengl_example/imgui_impl_sdl.cpp index 8359fd8a5..e222c806d 100644 --- a/examples/sdl_opengl_example/imgui_impl_sdl.cpp +++ b/examples/sdl_opengl_example/imgui_impl_sdl.cpp @@ -240,6 +240,10 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window) SDL_GetWindowSize(window, &w, &h); io.DisplaySize = ImVec2((float)w, (float)h); + int glW, glH; + SDL_GL_GetDrawableSize(window, &glW, &glH); + io.DisplayFramebufferScale = ImVec2(glW / io.DisplaySize.x, glH / io.DisplaySize.y); + // Setup time step Uint32 time = SDL_GetTicks(); double current_time = time / 1000.0; From 8a61c0afeae9209c5a11ecfb50bbe4737e8edcbc Mon Sep 17 00:00:00 2001 From: Nick Gravelyn Date: Wed, 20 Jan 2016 06:11:28 -0800 Subject: [PATCH 2/4] Applying same fix to OpenGL 3 example. Fixing spaces/tabs. --- examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp | 5 ++++- examples/sdl_opengl_example/imgui_impl_sdl.cpp | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp index bf47a7a19..db76fb464 100644 --- a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp +++ b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp @@ -352,7 +352,10 @@ void ImGui_ImplSdlGL3_NewFrame() int w, h; SDL_GetWindowSize(g_Window, &w, &h); io.DisplaySize = ImVec2((float)w, (float)h); - io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f); + + int glW, glH; + SDL_GL_GetDrawableSize(window, &glW, &glH); + io.DisplayFramebufferScale = ImVec2(glW / io.DisplaySize.x, glH / io.DisplaySize.y); // Setup time step Uint32 time = SDL_GetTicks(); diff --git a/examples/sdl_opengl_example/imgui_impl_sdl.cpp b/examples/sdl_opengl_example/imgui_impl_sdl.cpp index e222c806d..47dac65b2 100644 --- a/examples/sdl_opengl_example/imgui_impl_sdl.cpp +++ b/examples/sdl_opengl_example/imgui_impl_sdl.cpp @@ -240,9 +240,9 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window) SDL_GetWindowSize(window, &w, &h); io.DisplaySize = ImVec2((float)w, (float)h); - int glW, glH; - SDL_GL_GetDrawableSize(window, &glW, &glH); - io.DisplayFramebufferScale = ImVec2(glW / io.DisplaySize.x, glH / io.DisplaySize.y); + int glW, glH; + SDL_GL_GetDrawableSize(window, &glW, &glH); + io.DisplayFramebufferScale = ImVec2(glW / io.DisplaySize.x, glH / io.DisplaySize.y); // Setup time step Uint32 time = SDL_GetTicks(); From e6c2c1fcfd31a53a0411b1a844a3016e701d1ab7 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 25 Mar 2016 22:25:20 +0100 Subject: [PATCH 3/4] Examples: SDL: Minor fixes to follow syntax of other examples (#495) --- examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp | 7 +++---- examples/sdl_opengl_example/imgui_impl_sdl.cpp | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp index db76fb464..a5c4c9d06 100644 --- a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp +++ b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp @@ -350,12 +350,11 @@ void ImGui_ImplSdlGL3_NewFrame() // Setup display size (every frame to accommodate for window resizing) int w, h; + int display_w, display_h; SDL_GetWindowSize(g_Window, &w, &h); + SDL_GL_GetDrawableSize(g_Window, &display_w, &display_h); io.DisplaySize = ImVec2((float)w, (float)h); - - int glW, glH; - SDL_GL_GetDrawableSize(window, &glW, &glH); - io.DisplayFramebufferScale = ImVec2(glW / io.DisplaySize.x, glH / io.DisplaySize.y); + io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); // Setup time step Uint32 time = SDL_GetTicks(); diff --git a/examples/sdl_opengl_example/imgui_impl_sdl.cpp b/examples/sdl_opengl_example/imgui_impl_sdl.cpp index 47dac65b2..b84f5014d 100644 --- a/examples/sdl_opengl_example/imgui_impl_sdl.cpp +++ b/examples/sdl_opengl_example/imgui_impl_sdl.cpp @@ -237,12 +237,11 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window) // Setup display size (every frame to accommodate for window resizing) int w, h; + int display_w, display_h; SDL_GetWindowSize(window, &w, &h); + SDL_GL_GetDrawableSize(window, &display_w, &display_h); io.DisplaySize = ImVec2((float)w, (float)h); - - int glW, glH; - SDL_GL_GetDrawableSize(window, &glW, &glH); - io.DisplayFramebufferScale = ImVec2(glW / io.DisplaySize.x, glH / io.DisplaySize.y); + io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); // Setup time step Uint32 time = SDL_GetTicks(); From fdc4299c6ccfcabeb1316f42e43cc8129adf7a4f Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 25 Mar 2016 22:27:43 +0100 Subject: [PATCH 4/4] Examples: SDL: Made ImGui_ImplSdlGL3_NewFrame() signature match GL2 one --- examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp | 13 +++++-------- examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h | 4 ++-- examples/sdl_opengl3_example/main.cpp | 2 +- examples/sdl_opengl_example/imgui_impl_sdl.cpp | 2 +- examples/sdl_opengl_example/imgui_impl_sdl.h | 4 ++-- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp index a5c4c9d06..7afbf3435 100644 --- a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp +++ b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp @@ -15,7 +15,6 @@ #include // Data -static SDL_Window* g_Window = NULL; static double g_Time = 0.0f; static bool g_MousePressed[3] = { false, false, false }; static float g_MouseWheel = 0.0f; @@ -296,10 +295,8 @@ void ImGui_ImplSdlGL3_InvalidateDeviceObjects() } } -bool ImGui_ImplSdlGL3_Init(SDL_Window *window) +bool ImGui_ImplSdlGL3_Init(SDL_Window* window) { - g_Window = window; - ImGuiIO& io = ImGui::GetIO(); io.KeyMap[ImGuiKey_Tab] = SDLK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. io.KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT; @@ -341,7 +338,7 @@ void ImGui_ImplSdlGL3_Shutdown() ImGui::Shutdown(); } -void ImGui_ImplSdlGL3_NewFrame() +void ImGui_ImplSdlGL3_NewFrame(SDL_Window* window) { if (!g_FontTexture) ImGui_ImplSdlGL3_CreateDeviceObjects(); @@ -351,8 +348,8 @@ void ImGui_ImplSdlGL3_NewFrame() // Setup display size (every frame to accommodate for window resizing) int w, h; int display_w, display_h; - SDL_GetWindowSize(g_Window, &w, &h); - SDL_GL_GetDrawableSize(g_Window, &display_w, &display_h); + SDL_GetWindowSize(window, &w, &h); + SDL_GL_GetDrawableSize(window, &display_w, &display_h); io.DisplaySize = ImVec2((float)w, (float)h); io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0); @@ -366,7 +363,7 @@ void ImGui_ImplSdlGL3_NewFrame() // (we already got mouse wheel, keyboard keys & characters from SDL_PollEvent()) int mx, my; Uint32 mouseMask = SDL_GetMouseState(&mx, &my); - if (SDL_GetWindowFlags(g_Window) & SDL_WINDOW_MOUSE_FOCUS) + if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS) io.MousePos = ImVec2((float)mx, (float)my); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) else io.MousePos = ImVec2(-1, -1); diff --git a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h index 6205284a0..99abd4094 100644 --- a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h +++ b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h @@ -9,9 +9,9 @@ struct SDL_Window; typedef union SDL_Event SDL_Event; -IMGUI_API bool ImGui_ImplSdlGL3_Init(SDL_Window *window); +IMGUI_API bool ImGui_ImplSdlGL3_Init(SDL_Window* window); IMGUI_API void ImGui_ImplSdlGL3_Shutdown(); -IMGUI_API void ImGui_ImplSdlGL3_NewFrame(); +IMGUI_API void ImGui_ImplSdlGL3_NewFrame(SDL_Window* window); IMGUI_API bool ImGui_ImplSdlGL3_ProcessEvent(SDL_Event* event); // Use if you want to reset your rendering device without losing ImGui state. diff --git a/examples/sdl_opengl3_example/main.cpp b/examples/sdl_opengl3_example/main.cpp index 54d2749a6..33b4903f9 100644 --- a/examples/sdl_opengl3_example/main.cpp +++ b/examples/sdl_opengl3_example/main.cpp @@ -58,7 +58,7 @@ int main(int, char**) if (event.type == SDL_QUIT) done = true; } - ImGui_ImplSdlGL3_NewFrame(); + ImGui_ImplSdlGL3_NewFrame(window); // 1. Show a simple window // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" diff --git a/examples/sdl_opengl_example/imgui_impl_sdl.cpp b/examples/sdl_opengl_example/imgui_impl_sdl.cpp index b84f5014d..927f87749 100644 --- a/examples/sdl_opengl_example/imgui_impl_sdl.cpp +++ b/examples/sdl_opengl_example/imgui_impl_sdl.cpp @@ -185,7 +185,7 @@ void ImGui_ImplSdl_InvalidateDeviceObjects() } } -bool ImGui_ImplSdl_Init(SDL_Window *window) +bool ImGui_ImplSdl_Init(SDL_Window* window) { ImGuiIO& io = ImGui::GetIO(); io.KeyMap[ImGuiKey_Tab] = SDLK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. diff --git a/examples/sdl_opengl_example/imgui_impl_sdl.h b/examples/sdl_opengl_example/imgui_impl_sdl.h index e298365d2..a322bf2d9 100644 --- a/examples/sdl_opengl_example/imgui_impl_sdl.h +++ b/examples/sdl_opengl_example/imgui_impl_sdl.h @@ -9,9 +9,9 @@ struct SDL_Window; typedef union SDL_Event SDL_Event; -IMGUI_API bool ImGui_ImplSdl_Init(SDL_Window *window); +IMGUI_API bool ImGui_ImplSdl_Init(SDL_Window* window); IMGUI_API void ImGui_ImplSdl_Shutdown(); -IMGUI_API void ImGui_ImplSdl_NewFrame(SDL_Window *window); +IMGUI_API void ImGui_ImplSdl_NewFrame(SDL_Window* window); IMGUI_API bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event); // Use if you want to reset your rendering device without losing ImGui state.