From 064153fca4d769c7020e04f6f16c69047583ffb3 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 17 Apr 2023 14:40:00 +0200 Subject: [PATCH 01/11] Version 1.89.6 WIP --- docs/CHANGELOG.txt | 9 +++++++++ imgui.cpp | 2 +- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 2 +- imgui_tables.cpp | 2 +- imgui_widgets.cpp | 2 +- 8 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8bde6703a031..5ad221bdbd08 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -31,6 +31,15 @@ HOW TO UPDATE? - Please report any issue! +----------------------------------------------------------------------- + VERSION 1.89.6 WIP (In Progress) +----------------------------------------------------------------------- + +Breaking changes: + +Other changes: + + ----------------------------------------------------------------------- VERSION 1.89.5 (Released 2023-04-13) ----------------------------------------------------------------------- diff --git a/imgui.cpp b/imgui.cpp index 6272b729e73c..449bf5aacb70 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 +// dear imgui, v1.89.6 WIP // (main code and documentation) // Help: diff --git a/imgui.h b/imgui.h index 6946d13f7115..0e1c3951fe77 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 +// dear imgui, v1.89.6 WIP // (headers) // Help: @@ -22,8 +22,8 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345') -#define IMGUI_VERSION "1.89.5" -#define IMGUI_VERSION_NUM 18950 +#define IMGUI_VERSION "1.89.6 WIP" +#define IMGUI_VERSION_NUM 18951 #define IMGUI_HAS_TABLE /* diff --git a/imgui_demo.cpp b/imgui_demo.cpp index fc8097cef70c..af3000e4de44 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 +// dear imgui, v1.89.6 WIP // (demo code) // Help: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 182ec8339cce..313bc0f3e66c 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 +// dear imgui, v1.89.6 WIP // (drawing and font code) /* diff --git a/imgui_internal.h b/imgui_internal.h index 70e60000dd9d..e17aaa4012f6 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 +// dear imgui, v1.89.6 WIP // (internal structures/api) // You may use this file to debug, understand or extend Dear ImGui features but we don't provide any guarantee of forward compatibility. diff --git a/imgui_tables.cpp b/imgui_tables.cpp index 6ec419d55440..a61a04f37795 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 +// dear imgui, v1.89.6 WIP // (tables and columns code) /* diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 1d4aee6dfa52..3f07ff7526da 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 +// dear imgui, v1.89.6 WIP // (widgets code) /* From f304603e13f8548f2126cbca3392636b9663c5ce Mon Sep 17 00:00:00 2001 From: Gereon V <72784429+GereonV@users.noreply.github.com> Date: Sun, 16 Apr 2023 00:45:21 +0200 Subject: [PATCH 02/11] Backends: GLUT: remove call to ImGui::NewFrame() from ImGui_ImplGLUT_NewFrame(). (#6337) --- backends/imgui_impl_glut.cpp | 4 +--- docs/CHANGELOG.txt | 4 ++++ examples/example_glut_opengl2/main.cpp | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backends/imgui_impl_glut.cpp b/backends/imgui_impl_glut.cpp index 4734e4927135..5a3e7cc1d546 100644 --- a/backends/imgui_impl_glut.cpp +++ b/backends/imgui_impl_glut.cpp @@ -21,6 +21,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-04-17: BREAKING: Removed call to ImGui::NewFrame() from ImGui_ImplGLUT_NewFrame(). Needs to be called from the main application loop, like with every other backends. // 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported). // 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). @@ -202,9 +203,6 @@ void ImGui_ImplGLUT_NewFrame() delta_time_ms = 1; io.DeltaTime = delta_time_ms / 1000.0f; g_Time = current_time; - - // Start the frame - ImGui::NewFrame(); } static void ImGui_ImplGLUT_UpdateKeyModifiers() diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 5ad221bdbd08..72771734cb53 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -37,9 +37,13 @@ HOW TO UPDATE? Breaking changes: +- Backends: GLUT: Removed call to ImGui::NewFrame() from ImGui_ImplGLUT_NewFrame(). + It needs to be called from the main app loop, like with every other backends. (#6337) [@GereonV] + Other changes: + ----------------------------------------------------------------------- VERSION 1.89.5 (Released 2023-04-13) ----------------------------------------------------------------------- diff --git a/examples/example_glut_opengl2/main.cpp b/examples/example_glut_opengl2/main.cpp index 9333d13a3998..b7a07e8bf62d 100644 --- a/examples/example_glut_opengl2/main.cpp +++ b/examples/example_glut_opengl2/main.cpp @@ -107,6 +107,7 @@ void MainLoopStep() // Start the Dear ImGui frame ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGLUT_NewFrame(); + ImGui::NewFrame(); // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). if (show_demo_window) From 055e71518eaa7001bc522bb9d0420bb266849c3c Mon Sep 17 00:00:00 2001 From: Gereon V <72784429+GereonV@users.noreply.github.com> Date: Mon, 17 Apr 2023 14:47:15 +0200 Subject: [PATCH 03/11] Backends: clear bits set in io.BackendFlags on backend Shutdown(). Clear BackendPlatformName. (#6334, #6335) Amended with fix for missing clear for ImGuiBackendFlags_HasGamepad. --- backends/imgui_impl_allegro5.cpp | 3 ++- backends/imgui_impl_android.cpp | 2 ++ backends/imgui_impl_dx10.cpp | 1 + backends/imgui_impl_dx11.cpp | 1 + backends/imgui_impl_dx12.cpp | 1 + backends/imgui_impl_dx9.cpp | 1 + backends/imgui_impl_glfw.cpp | 1 + backends/imgui_impl_glut.cpp | 2 ++ backends/imgui_impl_metal.mm | 6 ++++++ backends/imgui_impl_opengl3.cpp | 1 + backends/imgui_impl_osx.mm | 7 +++++++ backends/imgui_impl_sdl2.cpp | 1 + backends/imgui_impl_sdl3.cpp | 1 + backends/imgui_impl_sdlrenderer.cpp | 1 + backends/imgui_impl_vulkan.cpp | 1 + backends/imgui_impl_wgpu.cpp | 1 + backends/imgui_impl_win32.cpp | 1 + docs/CHANGELOG.txt | 3 +++ 18 files changed, 34 insertions(+), 1 deletion(-) diff --git a/backends/imgui_impl_allegro5.cpp b/backends/imgui_impl_allegro5.cpp index b7e77687cb12..ae91443ceb21 100644 --- a/backends/imgui_impl_allegro5.cpp +++ b/backends/imgui_impl_allegro5.cpp @@ -462,8 +462,9 @@ void ImGui_ImplAllegro5_Shutdown() if (bd->ClipboardTextData) al_free(bd->ClipboardTextData); - io.BackendPlatformUserData = nullptr; io.BackendPlatformName = io.BackendRendererName = nullptr; + io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_HasMouseCursors; IM_DELETE(bd); } diff --git a/backends/imgui_impl_android.cpp b/backends/imgui_impl_android.cpp index 029c2c527f34..48828ec20b05 100644 --- a/backends/imgui_impl_android.cpp +++ b/backends/imgui_impl_android.cpp @@ -269,6 +269,8 @@ bool ImGui_ImplAndroid_Init(ANativeWindow* window) void ImGui_ImplAndroid_Shutdown() { + ImGuiIO& io = ImGui::GetIO(); + io.BackendPlatformName = nullptr; } void ImGui_ImplAndroid_NewFrame() diff --git a/backends/imgui_impl_dx10.cpp b/backends/imgui_impl_dx10.cpp index e0743592949c..06edb0e0d6d5 100644 --- a/backends/imgui_impl_dx10.cpp +++ b/backends/imgui_impl_dx10.cpp @@ -567,6 +567,7 @@ void ImGui_ImplDX10_Shutdown() if (bd->pd3dDevice) { bd->pd3dDevice->Release(); } io.BackendRendererName = nullptr; io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; IM_DELETE(bd); } diff --git a/backends/imgui_impl_dx11.cpp b/backends/imgui_impl_dx11.cpp index 43fe8144d5c6..eaf4cf6d616e 100644 --- a/backends/imgui_impl_dx11.cpp +++ b/backends/imgui_impl_dx11.cpp @@ -583,6 +583,7 @@ void ImGui_ImplDX11_Shutdown() if (bd->pd3dDeviceContext) { bd->pd3dDeviceContext->Release(); } io.BackendRendererName = nullptr; io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; IM_DELETE(bd); } diff --git a/backends/imgui_impl_dx12.cpp b/backends/imgui_impl_dx12.cpp index 2e390d20cf12..8712fce71c44 100644 --- a/backends/imgui_impl_dx12.cpp +++ b/backends/imgui_impl_dx12.cpp @@ -739,6 +739,7 @@ void ImGui_ImplDX12_Shutdown() delete[] bd->pFrameResources; io.BackendRendererName = nullptr; io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; IM_DELETE(bd); } diff --git a/backends/imgui_impl_dx9.cpp b/backends/imgui_impl_dx9.cpp index 61e9d6ed07c7..28afa44e22d0 100644 --- a/backends/imgui_impl_dx9.cpp +++ b/backends/imgui_impl_dx9.cpp @@ -304,6 +304,7 @@ void ImGui_ImplDX9_Shutdown() if (bd->pd3dDevice) { bd->pd3dDevice->Release(); } io.BackendRendererName = nullptr; io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; IM_DELETE(bd); } diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index 2241b9d53785..31b22681bb5c 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -643,6 +643,7 @@ void ImGui_ImplGlfw_Shutdown() io.BackendPlatformName = nullptr; io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad); IM_DELETE(bd); } diff --git a/backends/imgui_impl_glut.cpp b/backends/imgui_impl_glut.cpp index 5a3e7cc1d546..3f911a13652f 100644 --- a/backends/imgui_impl_glut.cpp +++ b/backends/imgui_impl_glut.cpp @@ -191,6 +191,8 @@ void ImGui_ImplGLUT_InstallFuncs() void ImGui_ImplGLUT_Shutdown() { + ImGuiIO& io = ImGui::GetIO(); + io.BackendPlatformName = nullptr; } void ImGui_ImplGLUT_NewFrame() diff --git a/backends/imgui_impl_metal.mm b/backends/imgui_impl_metal.mm index e195a15b91aa..00f5c0c6559c 100644 --- a/backends/imgui_impl_metal.mm +++ b/backends/imgui_impl_metal.mm @@ -135,6 +135,12 @@ bool ImGui_ImplMetal_Init(id device) void ImGui_ImplMetal_Shutdown() { + ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData(); + IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); + ImGuiIO& io = ImGui::GetIO(); + io.BackendRendererName = nullptr; + io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; ImGui_ImplMetal_DestroyDeviceObjects(); ImGui_ImplMetal_DestroyBackendData(); } diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index 7bf26e666829..0a01a5f790da 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -355,6 +355,7 @@ void ImGui_ImplOpenGL3_Shutdown() ImGui_ImplOpenGL3_DestroyDeviceObjects(); io.BackendRendererName = nullptr; io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; IM_DELETE(bd); } diff --git a/backends/imgui_impl_osx.mm b/backends/imgui_impl_osx.mm index f92775ed872a..bf27478623ac 100644 --- a/backends/imgui_impl_osx.mm +++ b/backends/imgui_impl_osx.mm @@ -476,12 +476,19 @@ bool ImGui_ImplOSX_Init(NSView* view) void ImGui_ImplOSX_Shutdown() { ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData(); + IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?"); + ImGuiIO& io = ImGui::GetIO(); + bd->Observer = nullptr; if (bd->Monitor != nullptr) { [NSEvent removeMonitor:bd->Monitor]; bd->Monitor = nullptr; } + + io.BackendPlatformName = nullptr; + io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasGamepad); ImGui_ImplOSX_DestroyBackendData(); } diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp index 8ba4be2fccda..0721c2c26758 100644 --- a/backends/imgui_impl_sdl2.cpp +++ b/backends/imgui_impl_sdl2.cpp @@ -491,6 +491,7 @@ void ImGui_ImplSDL2_Shutdown() io.BackendPlatformName = nullptr; io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad); IM_DELETE(bd); } diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp index c03cfb59936a..5b0c82d953fc 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -425,6 +425,7 @@ void ImGui_ImplSDL3_Shutdown() io.BackendPlatformName = nullptr; io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad); IM_DELETE(bd); } diff --git a/backends/imgui_impl_sdlrenderer.cpp b/backends/imgui_impl_sdlrenderer.cpp index 998a53739aac..2d4308378201 100644 --- a/backends/imgui_impl_sdlrenderer.cpp +++ b/backends/imgui_impl_sdlrenderer.cpp @@ -86,6 +86,7 @@ void ImGui_ImplSDLRenderer_Shutdown() io.BackendRendererName = nullptr; io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; IM_DELETE(bd); } diff --git a/backends/imgui_impl_vulkan.cpp b/backends/imgui_impl_vulkan.cpp index bfc488c26ed4..c5ee279f827b 100644 --- a/backends/imgui_impl_vulkan.cpp +++ b/backends/imgui_impl_vulkan.cpp @@ -1000,6 +1000,7 @@ void ImGui_ImplVulkan_Shutdown() ImGui_ImplVulkan_DestroyDeviceObjects(); io.BackendRendererName = nullptr; io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; IM_DELETE(bd); } diff --git a/backends/imgui_impl_wgpu.cpp b/backends/imgui_impl_wgpu.cpp index 1355d7e78bbe..8da8e4575bf3 100644 --- a/backends/imgui_impl_wgpu.cpp +++ b/backends/imgui_impl_wgpu.cpp @@ -751,6 +751,7 @@ void ImGui_ImplWGPU_Shutdown() io.BackendRendererName = nullptr; io.BackendRendererUserData = nullptr; + io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; IM_DELETE(bd); } diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index ecdf910e9319..cfbe3a290cf9 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -178,6 +178,7 @@ void ImGui_ImplWin32_Shutdown() io.BackendPlatformName = nullptr; io.BackendPlatformUserData = nullptr; + io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad); IM_DELETE(bd); } diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 72771734cb53..aaec7c70aeb9 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -42,6 +42,9 @@ Breaking changes: Other changes: +- Backends: Clear bits sets io.BackendFlags on backend Shutdown(). (#6334, #6335] [@GereonV] + Potentially this would facilitate switching runtime backend mid-session. + ----------------------------------------------------------------------- From f94a8344f6fd99f13125bd3a34c461814172b657 Mon Sep 17 00:00:00 2001 From: Faisal Arshed Date: Mon, 17 Apr 2023 18:00:10 +0500 Subject: [PATCH 04/11] Fix minor typos in FAQ (#6328) --- docs/FAQ.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 1855f436d7b9..8dd0c44166b2 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -665,7 +665,7 @@ Yes. People have written game editors, data browsers, debuggers, profilers, and Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might require you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient, and powerful. -Dear ImGui is built to be efficient and scalable toward the needs for AAA-quality applications running all day. The IMGUI paradigm offers different opportunities for optimization that the more typical RMGUI paradigm. +Dear ImGui is built to be efficient and scalable toward the needs for AAA-quality applications running all day. The IMGUI paradigm offers different opportunities for optimization than the more typical RMGUI paradigm. ##### [Return to Index](#index) @@ -673,7 +673,7 @@ Dear ImGui is built to be efficient and scalable toward the needs for AAA-qualit ### Q: Can you reskin the look of Dear ImGui? -Somehow. You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, and fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Dear ImGui is NOT designed to create a user interface for games, although with ingenious use of the low-level API you can do it. +Somewhat. You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, and fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Dear ImGui is NOT designed to create a user interface for games, although with ingenious use of the low-level API you can do it. A reasonably skinned application may look like (screenshot from [#2529](https://github.com/ocornut/imgui/issues/2529#issuecomment-524281119)): ![minipars](https://user-images.githubusercontent.com/314805/63589441-d9794f00-c5b1-11e9-8d96-cfc1b93702f7.png) From e49d31a1c9988e5379b55f8bea97c062e1f1a844 Mon Sep 17 00:00:00 2001 From: lukaasm Date: Mon, 17 Apr 2023 23:02:36 +0200 Subject: [PATCH 05/11] Tables: do not show empty tooltip when user submits TableHeader with no label to display. (#6342) --- docs/CHANGELOG.txt | 2 ++ imgui_tables.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index aaec7c70aeb9..85f05c8a22f0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -42,6 +42,8 @@ Breaking changes: Other changes: +- Tables: Fixed a small miscalculation in TableHeader() leading to an empty tooltip + showing when a sorting column has no visible name. (#6342) [@lukaasm] - Backends: Clear bits sets io.BackendFlags on backend Shutdown(). (#6334, #6335] [@GereonV] Potentially this would facilitate switching runtime backend mid-session. diff --git a/imgui_tables.cpp b/imgui_tables.cpp index a61a04f37795..012235a3b68d 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -3007,7 +3007,7 @@ void ImGui::TableHeader(const char* label) } // Sort order arrow - const float ellipsis_max = cell_r.Max.x - w_arrow - w_sort_text; + const float ellipsis_max = ImMax(cell_r.Max.x - w_arrow - w_sort_text, label_pos.x); if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort)) { if (column->SortOrder != -1) From 0948cfc19e897a23f3ac954b5e1c7471b8b810f5 Mon Sep 17 00:00:00 2001 From: lukaasm Date: Mon, 17 Apr 2023 19:37:36 +0200 Subject: [PATCH 06/11] InputText: do not set WantTextInputNextFrame during the frame InputText is deactivated. (#6341) --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 85f05c8a22f0..911be774d4d0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -44,6 +44,8 @@ Other changes: - Tables: Fixed a small miscalculation in TableHeader() leading to an empty tooltip showing when a sorting column has no visible name. (#6342) [@lukaasm] +- InputText: Avoid setting io.WantTextInputNextFrame during the deactivation frame. + (#6341) [@lukaasm] - Backends: Clear bits sets io.BackendFlags on backend Shutdown(). (#6334, #6335] [@GereonV] Potentially this would facilitate switching runtime backend mid-session. diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 3f07ff7526da..ed38787dee7b 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4296,7 +4296,6 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget. // Down the line we should have a cleaner library-wide concept of Selected vs Active. g.ActiveIdAllowOverlap = !io.MouseDown[0]; - g.WantTextInputNextFrame = 1; // Edit in progress const float mouse_x = (io.MousePos.x - frame_bb.Min.x - style.FramePadding.x) + state->ScrollX; @@ -4735,8 +4734,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } // Release active ID at the end of the function (so e.g. pressing Return still does a final application of the value) - if (clear_active_id && g.ActiveId == id) + // Otherwise request text input ahead for next frame. + if (g.ActiveId == id && clear_active_id) ClearActiveID(); + else if (g.ActiveId == id) + g.WantTextInputNextFrame = 1; // Render frame if (!is_multiline) From d6a7aca2f4b7c269f776744de45ebf3a091a3d50 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 18 Apr 2023 15:47:29 +0200 Subject: [PATCH 07/11] Nav: Debug: tweak debug facilities. --- imgui.cpp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 449bf5aacb70..cdd4219a1199 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10739,26 +10739,29 @@ static bool ImGui::NavScoreItem(ImGuiNavItemData* result) } #if IMGUI_DEBUG_NAV_SCORING - char buf[128]; - if (IsMouseHoveringRect(cand.Min, cand.Max)) - { - ImFormatString(buf, IM_ARRAYSIZE(buf), "dbox (%.2f,%.2f->%.4f)\ndcen (%.2f,%.2f->%.4f)\nd (%.2f,%.2f->%.4f)\nnav %c, quadrant %c", dbx, dby, dist_box, dcx, dcy, dist_center, dax, day, dist_axial, "WENS"[g.NavMoveDir], "WENS"[quadrant]); - ImDrawList* draw_list = GetForegroundDrawList(window); - draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255,200,0,100)); - draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255,255,0,200)); - draw_list->AddRectFilled(cand.Max - ImVec2(4, 4), cand.Max + CalcTextSize(buf) + ImVec2(4, 4), IM_COL32(40,0,0,150)); - draw_list->AddText(cand.Max, ~0U, buf); - } - else if (g.IO.KeyCtrl) // Hold to preview score in matching quadrant. Press C to rotate. + char buf[200]; + if (g.IO.KeyCtrl) // Hold CTRL to preview score in matching quadrant. CTRL+Arrow to rotate. { if (quadrant == g.NavMoveDir) { ImFormatString(buf, IM_ARRAYSIZE(buf), "%.0f/%.0f", dist_box, dist_center); ImDrawList* draw_list = GetForegroundDrawList(window); - draw_list->AddRectFilled(cand.Min, cand.Max, IM_COL32(255, 0, 0, 200)); + draw_list->AddRectFilled(cand.Min, cand.Max, IM_COL32(255, 0, 0, 80)); + draw_list->AddRectFilled(cand.Min, cand.Min + CalcTextSize(buf), IM_COL32(255, 0, 0, 200)); draw_list->AddText(cand.Min, IM_COL32(255, 255, 255, 255), buf); } } + if (IsMouseHoveringRect(cand.Min, cand.Max)) + { + ImFormatString(buf, IM_ARRAYSIZE(buf), + "d-box (%7.3f,%7.3f) -> %7.3f\nd-center (%7.3f,%7.3f) -> %7.3f\nd-axial (%7.3f,%7.3f) -> %7.3f\nnav %c, quadrant %c", + dbx, dby, dist_box, dcx, dcy, dist_center, dax, day, dist_axial, "WENS"[g.NavMoveDir], "WENS"[quadrant]); + ImDrawList* draw_list = GetForegroundDrawList(window); + draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255,200,0,100)); + draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255,255,0,200)); + draw_list->AddRectFilled(cand.Max - ImVec2(4, 4), cand.Max + CalcTextSize(buf) + ImVec2(4, 4), IM_COL32(40,0,0,200)); + draw_list->AddText(cand.Max, ~0U, buf); + } #endif // Is it in the quadrant we're interested in moving to? @@ -11378,13 +11381,14 @@ void ImGui::NavUpdateCreateMoveRequest() g.NavScoringNoClipRect.TranslateY(scoring_rect_offset_y); } - // [DEBUG] Always send a request + // [DEBUG] Always send a request when holding CTRL. Hold CTRL + Arrow change the direction. #if IMGUI_DEBUG_NAV_SCORING - if (io.KeyCtrl && IsKeyPressed(ImGuiKey_C)) - g.NavMoveDirForDebug = (ImGuiDir)((g.NavMoveDirForDebug + 1) & 3); - if (io.KeyCtrl && g.NavMoveDir == ImGuiDir_None) + //if (io.KeyCtrl && IsKeyPressed(ImGuiKey_C)) + // g.NavMoveDirForDebug = (ImGuiDir)((g.NavMoveDirForDebug + 1) & 3); + if (io.KeyCtrl) { - g.NavMoveDir = g.NavMoveDirForDebug; + if (g.NavMoveDir == ImGuiDir_None) + g.NavMoveDir = g.NavMoveDirForDebug; g.NavMoveFlags |= ImGuiNavMoveFlags_DebugNoResult; } #endif From d0836aa89a5e72e7cdaa165da6831740f97a053e Mon Sep 17 00:00:00 2001 From: Gereon V <72784429+GereonV@users.noreply.github.com> Date: Fri, 14 Apr 2023 22:49:50 +0200 Subject: [PATCH 08/11] Backends: OpenGL3: reset GL_POLYGON_MODE separately for front and back when possible. (#6333) --- backends/imgui_impl_opengl3.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index 0a01a5f790da..b4b4fc0a18e6 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -613,8 +613,24 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) #endif #ifdef IMGUI_IMPL_HAS_POLYGON_MODE - glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]); +// Desktop OpenGL 3.0 and OpenGL 3.1 had separate polygon draw modes for front-facing and back-facing faces of polygons +#if defined(GL_FRONT) && defined(GL_BACK) // possibly Desktop OpenGL 3.0, 3.1 or 3.2+ compatibility profile +#ifdef GL_CONTEXT_PROFILE_MASK // Desktop OpenGL 3.2+ + GLint profile_mask; + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile_mask); + if (profile_mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) +#else + if (bd->GlVersion <= 310) #endif + { + glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); + glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]); + } + else +#endif // GL_FRONT & GL_BACK + glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]); +#endif // IMGUI_IMPL_HAS_POLYGON_MODE + glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]); (void)bd; // Not all compilation paths use this From a338b78eb9b8a73dc049f8e54de1252e3a392f84 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 18 Apr 2023 12:01:40 +0200 Subject: [PATCH 09/11] Backends: OpenGL3: amend reset GL_POLYGON_MODE separately for front and back when possible. (#6333) --- backends/imgui_impl_opengl3.cpp | 23 ++++++++++++----------- backends/imgui_impl_opengl3_loader.h | 6 +++++- docs/CHANGELOG.txt | 2 ++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index b4b4fc0a18e6..b97992d57708 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -14,6 +14,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-04-18: OpenGL: Restore front and back polygon mode separately when supported by context. (#6333) // 2023-03-23: OpenGL: Properly restoring "no shader program bound" if it was the case prior to running the rendering function. (#6267, #6220, #6224) // 2023-03-15: OpenGL: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530) // 2023-03-06: OpenGL: Fixed restoration of a potentially deleted OpenGL program, by calling glIsProgram(). (#6220, #6224) @@ -204,6 +205,8 @@ struct ImGui_ImplOpenGL3_Data { GLuint GlVersion; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2) char GlslVersionString[32]; // Specified by user or detected based on compile time GL settings. + bool GlProfileIsCompat; + GLint GlProfileMask; GLuint FontTexture; GLuint ShaderHandle; GLint AttribLocationTex; // Uniforms location @@ -284,6 +287,10 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) sscanf(gl_version, "%d.%d", &major, &minor); } bd->GlVersion = (GLuint)(major * 100 + minor * 10); +#if defined(GL_CONTEXT_PROFILE_MASK) + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &bd->GlProfileMask); + bd->GlProfileIsCompat = (bd->GlProfileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0; +#endif bd->UseBufferSubData = false; /* @@ -613,22 +620,16 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) #endif #ifdef IMGUI_IMPL_HAS_POLYGON_MODE -// Desktop OpenGL 3.0 and OpenGL 3.1 had separate polygon draw modes for front-facing and back-facing faces of polygons -#if defined(GL_FRONT) && defined(GL_BACK) // possibly Desktop OpenGL 3.0, 3.1 or 3.2+ compatibility profile -#ifdef GL_CONTEXT_PROFILE_MASK // Desktop OpenGL 3.2+ - GLint profile_mask; - glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile_mask); - if (profile_mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) -#else - if (bd->GlVersion <= 310) -#endif + // Desktop OpenGL 3.0 and OpenGL 3.1 had separate polygon draw modes for front-facing and back-facing faces of polygons + if (bd->GlVersion <= 310 || bd->GlProfileIsCompat) { glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]); } else -#endif // GL_FRONT & GL_BACK - glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]); + { + glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]); + } #endif // IMGUI_IMPL_HAS_POLYGON_MODE glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); diff --git a/backends/imgui_impl_opengl3_loader.h b/backends/imgui_impl_opengl3_loader.h index af8d20c4841c..7ca72e378e12 100644 --- a/backends/imgui_impl_opengl3_loader.h +++ b/backends/imgui_impl_opengl3_loader.h @@ -118,7 +118,7 @@ extern "C" { ** included as . ** ** glcorearb.h includes only APIs in the latest OpenGL core profile -** implementation together with APIs in newer ARB extensions which +** implementation together with APIs in newer ARB extensions which ** can be supported by the core profile. It does not, and never will ** include functionality removed from the core profile, such as ** fixed-function vertex and fragment processing. @@ -154,6 +154,8 @@ typedef khronos_uint8_t GLubyte; #define GL_ONE 1 #define GL_SRC_ALPHA 0x0302 #define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 #define GL_FRONT_AND_BACK 0x0408 #define GL_POLYGON_MODE 0x0B40 #define GL_CULL_FACE 0x0B44 @@ -373,6 +375,8 @@ GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); typedef struct __GLsync *GLsync; typedef khronos_uint64_t GLuint64; typedef khronos_int64_t GLint64; +#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 +#define GL_CONTEXT_PROFILE_MASK 0x9126 typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); #ifdef GL_GLEXT_PROTOTYPES diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 911be774d4d0..d8d85e674f20 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -48,6 +48,8 @@ Other changes: (#6341) [@lukaasm] - Backends: Clear bits sets io.BackendFlags on backend Shutdown(). (#6334, #6335] [@GereonV] Potentially this would facilitate switching runtime backend mid-session. +- Backends: OpenGL3: Restore front and back polygon mode separately when supported + by context (Desktop 3.0, 3.1, or 3.2+ with compat bit). (#6333) [@GereonV] From a566ecc58ff3c71a1ab0f0d3a6cb58b46b684b80 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Sat, 9 May 2020 15:03:10 +0200 Subject: [PATCH 10/11] Examples: Add Win32/Winapi + OpenGL example. (#3218, #5170 and #6086, #2772, #2600, #2359, #2022, #1553) Removed mulit-viewpot stuff in this commit on master, will be re-added separately. --- backends/imgui_impl_win32.cpp | 56 +--- backends/imgui_impl_win32.h | 1 + .../example_win32_opengl3/build_win32.bat | 8 + .../example_win32_opengl3.vcxproj | 172 ++++++++++++ .../example_win32_opengl3.vcxproj.filters | 64 +++++ examples/example_win32_opengl3/main.cpp | 252 ++++++++++++++++++ examples/imgui_examples.sln | 10 + 7 files changed, 520 insertions(+), 43 deletions(-) create mode 100644 examples/example_win32_opengl3/build_win32.bat create mode 100644 examples/example_win32_opengl3/example_win32_opengl3.vcxproj create mode 100644 examples/example_win32_opengl3/example_win32_opengl3.vcxproj.filters create mode 100644 examples/example_win32_opengl3/main.cpp diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index cfbe3a290cf9..70c29f268d4d 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -114,7 +114,7 @@ static ImGui_ImplWin32_Data* ImGui_ImplWin32_GetBackendData() } // Functions -bool ImGui_ImplWin32_Init(void* hwnd) +static bool ImGui_ImplWin32_Init(void* hwnd, bool platformHasOwnDC) { ImGuiIO& io = ImGui::GetIO(); IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!"); @@ -139,6 +139,7 @@ bool ImGui_ImplWin32_Init(void* hwnd) // Set platform dependent data in viewport ImGui::GetMainViewport()->PlatformHandleRaw = (void*)hwnd; + IM_UNUSED(platformHasOwnDC); // Used in 'docking' branch // Dynamically load XInput library #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD @@ -164,6 +165,17 @@ bool ImGui_ImplWin32_Init(void* hwnd) return true; } +IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd) +{ + return ImGui_ImplWin32_Init(hwnd, false); +} + +IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd) +{ + // OpenGL needs CS_OWNDC + return ImGui_ImplWin32_Init(hwnd, true); +} + void ImGui_ImplWin32_Shutdown() { ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData(); @@ -804,45 +816,3 @@ float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd) HMONITOR monitor = ::MonitorFromWindow((HWND)hwnd, MONITOR_DEFAULTTONEAREST); return ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); } - -//--------------------------------------------------------------------------------------------------------- -// Transparency related helpers (optional) -//-------------------------------------------------------------------------------------------------------- - -#if defined(_MSC_VER) -#pragma comment(lib, "dwmapi") // Link with dwmapi.lib. MinGW will require linking with '-ldwmapi' -#endif - -// [experimental] -// Borrowed from GLFW's function updateFramebufferTransparency() in src/win32_window.c -// (the Dwm* functions are Vista era functions but we are borrowing logic from GLFW) -void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd) -{ - if (!_IsWindowsVistaOrGreater()) - return; - - BOOL composition; - if (FAILED(::DwmIsCompositionEnabled(&composition)) || !composition) - return; - - BOOL opaque; - DWORD color; - if (_IsWindows8OrGreater() || (SUCCEEDED(::DwmGetColorizationColor(&color, &opaque)) && !opaque)) - { - HRGN region = ::CreateRectRgn(0, 0, -1, -1); - DWM_BLURBEHIND bb = {}; - bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; - bb.hRgnBlur = region; - bb.fEnable = TRUE; - ::DwmEnableBlurBehindWindow((HWND)hwnd, &bb); - ::DeleteObject(region); - } - else - { - DWM_BLURBEHIND bb = {}; - bb.dwFlags = DWM_BB_ENABLE; - ::DwmEnableBlurBehindWindow((HWND)hwnd, &bb); - } -} - -//--------------------------------------------------------------------------------------------------------- diff --git a/backends/imgui_impl_win32.h b/backends/imgui_impl_win32.h index e1d5e4a533f9..ffffdea240fa 100644 --- a/backends/imgui_impl_win32.h +++ b/backends/imgui_impl_win32.h @@ -17,6 +17,7 @@ #include "imgui.h" // IMGUI_IMPL_API IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); +IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd); IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); diff --git a/examples/example_win32_opengl3/build_win32.bat b/examples/example_win32_opengl3/build_win32.bat new file mode 100644 index 000000000000..91cc6bec0e14 --- /dev/null +++ b/examples/example_win32_opengl3/build_win32.bat @@ -0,0 +1,8 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +@set OUT_DIR=Debug +@set OUT_EXE=example_win32_opengl3 +@set INCLUDES=/I..\.. /I..\..\backends +@set SOURCES=main.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\backends\imgui_impl_win32.cpp ..\..\imgui*.cpp +@set LIBS=opengl32.lib +mkdir %OUT_DIR% +cl /nologo /Zi /MD %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% diff --git a/examples/example_win32_opengl3/example_win32_opengl3.vcxproj b/examples/example_win32_opengl3/example_win32_opengl3.vcxproj new file mode 100644 index 000000000000..49023e3dcfdd --- /dev/null +++ b/examples/example_win32_opengl3/example_win32_opengl3.vcxproj @@ -0,0 +1,172 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {C624E5FF-D4FE-4D35-9164-B8A91864F98E} + example_win32_opengl2 + 8.1 + + + + Application + true + Unicode + v140 + + + Application + true + Unicode + v140 + + + Application + false + true + Unicode + v140 + + + Application + false + true + Unicode + v140 + + + + + + + + + + + + + + + + + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + + Level4 + Disabled + ..\..;..\..\backends; + + + true + %(AdditionalLibraryDirectories) + opengl32.lib;%(AdditionalDependencies) + Console + + + + + Level4 + Disabled + ..\..;..\..\backends; + + + true + %(AdditionalLibraryDirectories) + opengl32.lib;%(AdditionalDependencies) + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;..\..\backends; + false + + + true + true + true + %(AdditionalLibraryDirectories) + opengl32.lib;%(AdditionalDependencies) + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;..\..\backends; + false + + + true + true + true + %(AdditionalLibraryDirectories) + opengl32.lib;%(AdditionalDependencies) + Console + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/example_win32_opengl3/example_win32_opengl3.vcxproj.filters b/examples/example_win32_opengl3/example_win32_opengl3.vcxproj.filters new file mode 100644 index 000000000000..47ed299bc705 --- /dev/null +++ b/examples/example_win32_opengl3/example_win32_opengl3.vcxproj.filters @@ -0,0 +1,64 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {a82cba23-9de0-45c2-b1e3-2eb1666702de} + + + + + sources + + + imgui + + + imgui + + + imgui + + + imgui + + + sources + + + imgui + + + sources + + + + + imgui + + + imgui + + + imgui + + + sources + + + sources + + + sources + + + + + + sources + + + \ No newline at end of file diff --git a/examples/example_win32_opengl3/main.cpp b/examples/example_win32_opengl3/main.cpp new file mode 100644 index 000000000000..d35160748acf --- /dev/null +++ b/examples/example_win32_opengl3/main.cpp @@ -0,0 +1,252 @@ +// dear imgui: standalone example application for OpenGL3 with Winapi +// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. + +#include "imgui.h" +#include "imgui_impl_opengl3.h" +#include "imgui_impl_win32.h" +#include +#include +#include + +// Data stored per platform window +struct RendererData +{ + HDC hDC; +}; + +// Data +HGLRC g_hRC; +RendererData g_MainWindow; +static int g_Width; +static int g_Height; + +// Forward declarations of helper functions +static bool CreateDeviceOpenGL3(HWND hWnd, RendererData* data); +static void CleanupDeviceOpenGL3(HWND hWnd, RendererData* data); +LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + +// Main code +int main(int, char**) +{ + // Create application window + //ImGui_ImplWin32_EnableDpiAwareness(); + WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_OWNDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL }; + ::RegisterClassEx(&wc); + HWND hwnd = ::CreateWindow(wc.lpszClassName, _T("Dear ImGui Winapi+OpenGL3 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); + + // Initialize OpenGL3 + if (!CreateDeviceOpenGL3(hwnd, &g_MainWindow)) + { + CleanupDeviceOpenGL3(hwnd, &g_MainWindow); + ::DestroyWindow(hwnd); + ::UnregisterClass(wc.lpszClassName, wc.hInstance); + return 1; + } + + wglMakeCurrent(g_MainWindow.hDC, g_hRC); + + // Show the window + ::ShowWindow(hwnd, SW_SHOWDEFAULT); + ::UpdateWindow(hwnd); + + // Setup Dear ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsClassic(); + + // Setup Platform/Renderer bindings + ImGui_ImplWin32_InitForOpenGL(hwnd); + ImGui_ImplOpenGL3_Init(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'docs/FONTS.md' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + // Our state + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + MSG msg; + ZeroMemory(&msg, sizeof(msg)); + while (msg.message != WM_QUIT) + { + // Poll and handle messages (inputs, window resize, etc.) + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + if (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) + { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + continue; + } + + // Start the Dear ImGui frame + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplWin32_NewFrame(); + ImGui::NewFrame(); + + // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). + if (show_demo_window) + ImGui::ShowDemoWindow(&show_demo_window); + + // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window. + { + static float f = 0.0f; + static int counter = 0; + + ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. + + ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) + ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state + ImGui::Checkbox("Another Window", &show_another_window); + + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color + + if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) + counter++; + ImGui::SameLine(); + ImGui::Text("counter = %d", counter); + + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + ImGui::End(); + } + + // 3. Show another simple window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) + ImGui::Text("Hello from another window!"); + if (ImGui::Button("Close Me")) + show_another_window = false; + ImGui::End(); + } + + // Rendering + ImGui::Render(); + glViewport(0, 0, g_Width, g_Height); + glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); + glClear(GL_COLOR_BUFFER_BIT); + + // If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!), + // you may need to backup/reset/restore current shader using the commented lines below. + //GLint last_program; + //glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); + //glUseProgram(0); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + //glUseProgram(last_program); + + SwapBuffers(g_MainWindow.hDC); + } + + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplWin32_Shutdown(); + ImGui::DestroyContext(); + + CleanupDeviceOpenGL3(hwnd, &g_MainWindow); + wglDeleteContext(g_hRC); + ::DestroyWindow(hwnd); + ::UnregisterClass(wc.lpszClassName, wc.hInstance); + + return 0; +} + +static bool ActivateOpenGL3(HWND hWnd) +{ + HDC hDc = GetDC(hWnd); + + PIXELFORMATDESCRIPTOR pfd = { 0 }; + + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = 32; + + int pf = ChoosePixelFormat(hDc, &pfd); + if (pf == 0) + { + return false; + } + + if (SetPixelFormat(hDc, pf, &pfd) == FALSE) + { + return false; + } + + ReleaseDC(hWnd, hDc); + return true; +} + +// Helper functions + +static bool CreateDeviceOpenGL3(HWND hWnd, RendererData* data) +{ + if (!ActivateOpenGL3(hWnd)) + return false; + + data->hDC = GetDC(hWnd); + + if (!g_hRC) + { + g_hRC = wglCreateContext(data->hDC); + } + + return true; +} + +static void CleanupDeviceOpenGL3(HWND hWnd, RendererData* data) +{ + wglMakeCurrent(NULL, NULL); + ReleaseDC(hWnd, data->hDC); +} + +// Forward declare message handler from imgui_impl_win32.cpp +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + +// Win32 message handler +LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) + return true; + + switch (msg) + { + case WM_SIZE: + if (wParam != SIZE_MINIMIZED) + { + g_Width = LOWORD(lParam); + g_Height = HIWORD(lParam); + } + return 0; + case WM_SYSCOMMAND: + if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu + return 0; + break; + case WM_DESTROY: + ::PostQuitMessage(0); + return 0; + } + return ::DefWindowProc(hWnd, msg, wParam, lParam); +} diff --git a/examples/imgui_examples.sln b/examples/imgui_examples.sln index 9b442b276f99..263f8bc4f64d 100644 --- a/examples/imgui_examples.sln +++ b/examples/imgui_examples.sln @@ -27,6 +27,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_sdl2_sdlrenderer", EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_sdl2_vulkan", "example_sdl2_vulkan\example_sdl2_vulkan.vcxproj", "{BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_win32_opengl3", "example_win32_opengl3\example_win32_opengl3.vcxproj", "{C624E5FF-D4FE-4D35-9164-B8A91864F98E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -131,6 +133,14 @@ Global {BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}.Release|Win32.Build.0 = Release|Win32 {BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}.Release|x64.ActiveCfg = Release|x64 {BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}.Release|x64.Build.0 = Release|x64 + {C624E5FF-D4FE-4D35-9164-B8A91864F98E}.Debug|Win32.ActiveCfg = Debug|Win32 + {C624E5FF-D4FE-4D35-9164-B8A91864F98E}.Debug|Win32.Build.0 = Debug|Win32 + {C624E5FF-D4FE-4D35-9164-B8A91864F98E}.Debug|x64.ActiveCfg = Debug|x64 + {C624E5FF-D4FE-4D35-9164-B8A91864F98E}.Debug|x64.Build.0 = Debug|x64 + {C624E5FF-D4FE-4D35-9164-B8A91864F98E}.Release|Win32.ActiveCfg = Release|Win32 + {C624E5FF-D4FE-4D35-9164-B8A91864F98E}.Release|Win32.Build.0 = Release|Win32 + {C624E5FF-D4FE-4D35-9164-B8A91864F98E}.Release|x64.ActiveCfg = Release|x64 + {C624E5FF-D4FE-4D35-9164-B8A91864F98E}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 9308cfdcfb83c74137f2996c7fc8c2d043436ba5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 19 Apr 2023 15:57:38 +0200 Subject: [PATCH 11/11] Examples: Amend Win32/Winapi + OpenGL example. (#3218, #5170 and #6086, #2772, #2600, #2359, #2022, #1553) --- backends/imgui_impl_win32.cpp | 9 +- docs/CHANGELOG.txt | 4 + docs/EXAMPLES.md | 4 + examples/example_win32_opengl3/main.cpp | 128 ++++++++++-------------- 4 files changed, 68 insertions(+), 77 deletions(-) diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index 70c29f268d4d..363e016d85d8 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -35,6 +35,7 @@ typedef DWORD (WINAPI *PFN_XInputGetState)(DWORD, XINPUT_STATE*); // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-04-19: Added ImGui_ImplWin32_InitForOpenGL() to facilitate combining raw Win32/Winapi with OpenGL. (#3218) // 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen. (#2702) // 2023-02-15: Inputs: Use WM_NCMOUSEMOVE / WM_NCMOUSELEAVE to track mouse position over non-client area (e.g. OS decorations) when app is not focused. (#6045, #6162) // 2023-02-02: Inputs: Flipping WM_MOUSEHWHEEL (horizontal mouse-wheel) value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463) @@ -114,7 +115,7 @@ static ImGui_ImplWin32_Data* ImGui_ImplWin32_GetBackendData() } // Functions -static bool ImGui_ImplWin32_Init(void* hwnd, bool platformHasOwnDC) +static bool ImGui_ImplWin32_InitEx(void* hwnd, bool platform_has_own_dc) { ImGuiIO& io = ImGui::GetIO(); IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!"); @@ -139,7 +140,7 @@ static bool ImGui_ImplWin32_Init(void* hwnd, bool platformHasOwnDC) // Set platform dependent data in viewport ImGui::GetMainViewport()->PlatformHandleRaw = (void*)hwnd; - IM_UNUSED(platformHasOwnDC); // Used in 'docking' branch + IM_UNUSED(platform_has_own_dc); // Used in 'docking' branch // Dynamically load XInput library #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD @@ -167,13 +168,13 @@ static bool ImGui_ImplWin32_Init(void* hwnd, bool platformHasOwnDC) IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd) { - return ImGui_ImplWin32_Init(hwnd, false); + return ImGui_ImplWin32_InitEx(hwnd, false); } IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd) { // OpenGL needs CS_OWNDC - return ImGui_ImplWin32_Init(hwnd, true); + return ImGui_ImplWin32_InitEx(hwnd, true); } void ImGui_ImplWin32_Shutdown() diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d8d85e674f20..a887cb5a0008 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -48,8 +48,12 @@ Other changes: (#6341) [@lukaasm] - Backends: Clear bits sets io.BackendFlags on backend Shutdown(). (#6334, #6335] [@GereonV] Potentially this would facilitate switching runtime backend mid-session. +- Backends: Win32: Added ImGui_ImplWin32_InitForOpenGL() to facilitate combining raw + Win32/Winapi with OpenGL. (#3218) - Backends: OpenGL3: Restore front and back polygon mode separately when supported by context (Desktop 3.0, 3.1, or 3.2+ with compat bit). (#6333) [@GereonV] +- Examples: Added native Win32+OpenGL3 example. We don't recommend using this setup but we + provide it for completeness. (#3218, #5170, #6086, #2772, #2600, #2359, #2022, #1553) [@learn-more] diff --git a/docs/EXAMPLES.md b/docs/EXAMPLES.md index d6d1bb6504fd..42ff478508d4 100644 --- a/docs/EXAMPLES.md +++ b/docs/EXAMPLES.md @@ -200,6 +200,10 @@ DirectX12 example, Windows only.
= main.cpp + imgui_impl_win32.cpp + imgui_impl_dx12.cpp
This is quite long and tedious, because: DirectX12. +[example_win32_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_win32_opengl3/)
+Raw Windows + OpenGL3 + example (modern, programmable pipeline)
+= main.cpp + imgui_impl_win32.cpp + imgui_impl_opengl3.cpp
+ ### Miscellaneous diff --git a/examples/example_win32_opengl3/main.cpp b/examples/example_win32_opengl3/main.cpp index d35160748acf..7b89a0a12578 100644 --- a/examples/example_win32_opengl3/main.cpp +++ b/examples/example_win32_opengl3/main.cpp @@ -1,28 +1,32 @@ -// dear imgui: standalone example application for OpenGL3 with Winapi -// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. +// Dear ImGui: standalone example application for Win32 + OpenGL 3 +// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. +// Read online: https://github.com/ocornut/imgui/tree/master/docs + +// This is provided for completeness, however it is strogly recommended you use OpenGL with SDL or GLFW. #include "imgui.h" #include "imgui_impl_opengl3.h" #include "imgui_impl_win32.h" +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif #include #include #include // Data stored per platform window -struct RendererData -{ - HDC hDC; -}; +struct WGL_WindowData { HDC hDC; }; // Data -HGLRC g_hRC; -RendererData g_MainWindow; -static int g_Width; -static int g_Height; +static HGLRC g_hRC; +static WGL_WindowData g_MainWindow; +static int g_Width; +static int g_Height; // Forward declarations of helper functions -static bool CreateDeviceOpenGL3(HWND hWnd, RendererData* data); -static void CleanupDeviceOpenGL3(HWND hWnd, RendererData* data); +bool CreateDeviceWGL(HWND hWnd, WGL_WindowData* data); +void CleanupDeviceWGL(HWND hWnd, WGL_WindowData* data); +void ResetDeviceWGL(); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); // Main code @@ -30,19 +34,18 @@ int main(int, char**) { // Create application window //ImGui_ImplWin32_EnableDpiAwareness(); - WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_OWNDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL }; - ::RegisterClassEx(&wc); - HWND hwnd = ::CreateWindow(wc.lpszClassName, _T("Dear ImGui Winapi+OpenGL3 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); + WNDCLASSEXW wc = { sizeof(wc), CS_OWNDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, L"ImGui Example", NULL }; + ::RegisterClassExW(&wc); + HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"Dear ImGui Win32+OpenGL3 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); - // Initialize OpenGL3 - if (!CreateDeviceOpenGL3(hwnd, &g_MainWindow)) + // Initialize OpenGL + if (!CreateDeviceWGL(hwnd, &g_MainWindow)) { - CleanupDeviceOpenGL3(hwnd, &g_MainWindow); + CleanupDeviceWGL(hwnd, &g_MainWindow); ::DestroyWindow(hwnd); - ::UnregisterClass(wc.lpszClassName, wc.hInstance); + ::UnregisterClassW(wc.lpszClassName, wc.hInstance); return 1; } - wglMakeCurrent(g_MainWindow.hDC, g_hRC); // Show the window @@ -60,7 +63,7 @@ int main(int, char**) ImGui::StyleColorsDark(); //ImGui::StyleColorsClassic(); - // Setup Platform/Renderer bindings + // Setup Platform/Renderer backends ImGui_ImplWin32_InitForOpenGL(hwnd); ImGui_ImplOpenGL3_Init(); @@ -69,13 +72,14 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering. // - Read 'docs/FONTS.md' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); @@ -85,21 +89,21 @@ int main(int, char**) ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); // Main loop - MSG msg; - ZeroMemory(&msg, sizeof(msg)); - while (msg.message != WM_QUIT) + bool done = false; + while (!done) { // Poll and handle messages (inputs, window resize, etc.) - // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. - // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. - // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. - // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. - if (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) + // See the WndProc() function below for our to dispatch events to the Win32 backend. + MSG msg; + while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); - continue; + if (msg.message == WM_QUIT) + done = true; } + if (done) + break; // Start the Dear ImGui frame ImGui_ImplOpenGL3_NewFrame(); @@ -110,7 +114,7 @@ int main(int, char**) if (show_demo_window) ImGui::ShowDemoWindow(&show_demo_window); - // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window. + // 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window. { static float f = 0.0f; static int counter = 0; @@ -129,7 +133,7 @@ int main(int, char**) ImGui::SameLine(); ImGui::Text("counter = %d", counter); - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); ImGui::End(); } @@ -148,84 +152,62 @@ int main(int, char**) glViewport(0, 0, g_Width, g_Height); glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); glClear(GL_COLOR_BUFFER_BIT); - - // If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!), - // you may need to backup/reset/restore current shader using the commented lines below. - //GLint last_program; - //glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); - //glUseProgram(0); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - //glUseProgram(last_program); - SwapBuffers(g_MainWindow.hDC); + // Present + ::SwapBuffers(g_MainWindow.hDC); } ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplWin32_Shutdown(); ImGui::DestroyContext(); - CleanupDeviceOpenGL3(hwnd, &g_MainWindow); + CleanupDeviceWGL(hwnd, &g_MainWindow); wglDeleteContext(g_hRC); ::DestroyWindow(hwnd); - ::UnregisterClass(wc.lpszClassName, wc.hInstance); + ::UnregisterClassW(wc.lpszClassName, wc.hInstance); return 0; } -static bool ActivateOpenGL3(HWND hWnd) +// Helper functions +bool CreateDeviceWGL(HWND hWnd, WGL_WindowData* data) { - HDC hDc = GetDC(hWnd); - + HDC hDc = ::GetDC(hWnd); PIXELFORMATDESCRIPTOR pfd = { 0 }; - pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; - int pf = ChoosePixelFormat(hDc, &pfd); + const int pf = ::ChoosePixelFormat(hDc, &pfd); if (pf == 0) - { - return false; - } - - if (SetPixelFormat(hDc, pf, &pfd) == FALSE) - { return false; - } - - ReleaseDC(hWnd, hDc); - return true; -} - -// Helper functions - -static bool CreateDeviceOpenGL3(HWND hWnd, RendererData* data) -{ - if (!ActivateOpenGL3(hWnd)) + if (::SetPixelFormat(hDc, pf, &pfd) == FALSE) return false; + ::ReleaseDC(hWnd, hDc); - data->hDC = GetDC(hWnd); - + data->hDC = ::GetDC(hWnd); if (!g_hRC) - { g_hRC = wglCreateContext(data->hDC); - } - return true; } -static void CleanupDeviceOpenGL3(HWND hWnd, RendererData* data) +void CleanupDeviceWGL(HWND hWnd, WGL_WindowData* data) { wglMakeCurrent(NULL, NULL); - ReleaseDC(hWnd, data->hDC); + ::ReleaseDC(hWnd, data->hDC); } // Forward declare message handler from imgui_impl_win32.cpp extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); // Win32 message handler +// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. +// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. +// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))