From 8c374512fdaa1918c155c1e65a81e5f5e08ed094 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 7 Jun 2018 22:10:31 +0200 Subject: [PATCH] Examples, Platform: Removed the call to ImGui::NewFrame() from the platform _NewFrame() function e.g. ImGui_ImplWin32_NewFrame(), ImGui_ImplSDL2_NewFrame(), ImGui_ImplGlfw_NewFrame(), etc. Moved to main.cpp for consistency. (#1542) --- examples/allegro5_example/main.cpp | 6 +++++- examples/directx10_example/main.cpp | 6 +++++- examples/directx11_example/main.cpp | 6 +++++- examples/directx12_example/main.cpp | 6 +++++- examples/directx9_example/main.cpp | 4 ++++ examples/imgui_impl_allegro5.cpp | 3 --- examples/imgui_impl_glfw.cpp | 3 --- examples/imgui_impl_marmalade.cpp | 3 --- examples/imgui_impl_sdl2.cpp | 3 --- examples/imgui_impl_win32.cpp | 3 --- examples/marmalade_example/main.cpp | 6 +++++- examples/opengl2_example/main.cpp | 4 ++++ examples/opengl3_example/main.cpp | 4 ++++ examples/sdl_opengl2_example/main.cpp | 6 +++++- examples/sdl_opengl3_example/main.cpp | 4 ++++ examples/sdl_vulkan_example/main.cpp | 4 ++++ examples/vulkan_example/main.cpp | 4 +++- imgui.cpp | 2 ++ 18 files changed, 55 insertions(+), 22 deletions(-) diff --git a/examples/allegro5_example/main.cpp b/examples/allegro5_example/main.cpp index c04e1772..3c0d8f62 100644 --- a/examples/allegro5_example/main.cpp +++ b/examples/allegro5_example/main.cpp @@ -56,6 +56,7 @@ int main(int, char**) bool running = true; while (running) { + // Poll and handle events (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. @@ -73,7 +74,10 @@ int main(int, char**) ImGui_ImplAllegro5_CreateDeviceObjects(); } } + + // Start the ImGui frame ImGui_ImplAllegro5_NewFrame(); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". @@ -113,8 +117,8 @@ int main(int, char**) } // Rendering - al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w)); ImGui::Render(); + al_clear_to_color(al_map_rgba_f(clear_color.x, clear_color.y, clear_color.z, clear_color.w)); ImGui_ImplAllegro5_RenderDrawData(ImGui::GetDrawData()); al_flip_display(); } diff --git a/examples/directx10_example/main.cpp b/examples/directx10_example/main.cpp index 704c8bd9..3cca8239 100644 --- a/examples/directx10_example/main.cpp +++ b/examples/directx10_example/main.cpp @@ -153,6 +153,7 @@ int main(int, char**) 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. @@ -163,8 +164,11 @@ int main(int, char**) DispatchMessage(&msg); continue; } + + // Start the ImGui frame ImGui_ImplDX10_NewFrame(); ImGui_ImplWin32_NewFrame(); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". @@ -204,9 +208,9 @@ int main(int, char**) } // Rendering + ImGui::Render(); g_pd3dDevice->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); g_pd3dDevice->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color); - ImGui::Render(); ImGui_ImplDX10_RenderDrawData(ImGui::GetDrawData()); // Update and Render additional Platform Windows diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index ad3f697a..f36567e7 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -173,6 +173,7 @@ int main(int, char**) 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. @@ -183,8 +184,11 @@ int main(int, char**) DispatchMessage(&msg); continue; } + + // Start the ImGui frame ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". @@ -224,9 +228,9 @@ int main(int, char**) } // Rendering + ImGui::Render(); g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color); - ImGui::Render(); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); // Update and Render additional Platform Windows diff --git a/examples/directx12_example/main.cpp b/examples/directx12_example/main.cpp index 89230e5d..1eec041f 100644 --- a/examples/directx12_example/main.cpp +++ b/examples/directx12_example/main.cpp @@ -290,7 +290,7 @@ int main(int, char**) IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; - io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; + //io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls ImGui_ImplWin32_Init(hwnd); @@ -325,6 +325,7 @@ int main(int, char**) 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. @@ -335,8 +336,11 @@ int main(int, char**) DispatchMessage(&msg); continue; } + + // Start the ImGui frame ImGui_ImplDX12_NewFrame(g_pd3dCommandList); ImGui_ImplWin32_NewFrame(); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index a7333a5d..458f516a 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -113,6 +113,7 @@ int main(int, char**) UpdateWindow(hwnd); 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. @@ -123,8 +124,11 @@ int main(int, char**) DispatchMessage(&msg); continue; } + + // Start the ImGui frame ImGui_ImplDX9_NewFrame(); ImGui_ImplWin32_NewFrame(); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". diff --git a/examples/imgui_impl_allegro5.cpp b/examples/imgui_impl_allegro5.cpp index 3a2a88a8..93ae78f8 100644 --- a/examples/imgui_impl_allegro5.cpp +++ b/examples/imgui_impl_allegro5.cpp @@ -307,7 +307,4 @@ void ImGui_ImplAllegro5_NewFrame() } al_set_system_mouse_cursor(g_Display, cursor_id); } - - // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. - ImGui::NewFrame(); } diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index e03e93bc..b33c6990 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -326,9 +326,6 @@ void ImGui_ImplGlfw_NewFrame() else io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; } - - // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. - ImGui::NewFrame(); } //-------------------------------------------------------------------------------------------------------- diff --git a/examples/imgui_impl_marmalade.cpp b/examples/imgui_impl_marmalade.cpp index 680c16e1..58c70be2 100644 --- a/examples/imgui_impl_marmalade.cpp +++ b/examples/imgui_impl_marmalade.cpp @@ -289,9 +289,6 @@ void ImGui_Marmalade_NewFrame() // TODO: Hide OS mouse cursor if ImGui is drawing it // s3ePointerSetInt(S3E_POINTER_HIDE_CURSOR,(io.MouseDrawCursor ? 0 : 1)); - // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. - ImGui::NewFrame(); - // Show/hide OSD keyboard if (io.WantTextInput) { diff --git a/examples/imgui_impl_sdl2.cpp b/examples/imgui_impl_sdl2.cpp index eee40265..c21f0319 100644 --- a/examples/imgui_impl_sdl2.cpp +++ b/examples/imgui_impl_sdl2.cpp @@ -302,9 +302,6 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window) ImGui_ImplSDL2_UpdateMousePosAndButtons(); ImGui_ImplSDL2_UpdateMouseCursor(); - - // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. - ImGui::NewFrame(); } //-------------------------------------------------------------------------------------------------------- diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index f43ebd0c..9debebc5 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -203,9 +203,6 @@ void ImGui_ImplWin32_NewFrame() g_LastMouseCursor = mouse_cursor; ImGui_ImplWin32_UpdateMouseCursor(); } - - // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. - ImGui::NewFrame(); } // Allow compilation with old Windows SDK. MinGW doesn't have default _WIN32_WINNT/WINVER versions. diff --git a/examples/marmalade_example/main.cpp b/examples/marmalade_example/main.cpp index 3fcf1526..c09ab7dd 100644 --- a/examples/marmalade_example/main.cpp +++ b/examples/marmalade_example/main.cpp @@ -52,13 +52,17 @@ int main(int, char**) if (s3eDeviceCheckQuitRequest()) break; + // Poll and handle inputs // 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. s3eKeyboardUpdate(); s3ePointerUpdate(); + + // Start the ImGui frame ImGui_Marmalade_NewFrame(); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". @@ -98,9 +102,9 @@ int main(int, char**) } // Rendering + ImGui::Render(); IwGxSetColClear(clear_color.x * 255, clear_color.y * 255, clear_color.z * 255, clear_color.w * 255); IwGxClear(); - ImGui::Render(); ImGui_Marmalade_RenderDrawData(ImGui::GetDrawData()); IwGxSwapBuffers(); diff --git a/examples/opengl2_example/main.cpp b/examples/opengl2_example/main.cpp index eff0f300..e73e0afa 100644 --- a/examples/opengl2_example/main.cpp +++ b/examples/opengl2_example/main.cpp @@ -63,13 +63,17 @@ int main(int, char**) // Main loop while (!glfwWindowShouldClose(window)) { + // Poll and handle events (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. glfwPollEvents(); + + // Start the ImGui frame ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index be6c0357..06414b0c 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -72,13 +72,17 @@ int main(int, char**) // Main loop while (!glfwWindowShouldClose(window)) { + // Poll and handle events (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. glfwPollEvents(); + + // Start the ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". diff --git a/examples/sdl_opengl2_example/main.cpp b/examples/sdl_opengl2_example/main.cpp index 36c8ecf0..133ecb2b 100644 --- a/examples/sdl_opengl2_example/main.cpp +++ b/examples/sdl_opengl2_example/main.cpp @@ -70,6 +70,7 @@ int main(int, char**) bool done = false; while (!done) { + // Poll and handle events (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. @@ -81,8 +82,11 @@ int main(int, char**) if (event.type == SDL_QUIT) done = true; } + + // Start the ImGui frame ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplSDL2_NewFrame(window); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". @@ -122,11 +126,11 @@ int main(int, char**) } // Rendering + ImGui::Render(); glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); glClear(GL_COLOR_BUFFER_BIT); //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound - ImGui::Render(); ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); SDL_GL_SwapWindow(window); } diff --git a/examples/sdl_opengl3_example/main.cpp b/examples/sdl_opengl3_example/main.cpp index 69044527..f2a0e5a8 100644 --- a/examples/sdl_opengl3_example/main.cpp +++ b/examples/sdl_opengl3_example/main.cpp @@ -72,6 +72,7 @@ int main(int, char**) bool done = false; while (!done) { + // Poll and handle events (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. @@ -85,8 +86,11 @@ int main(int, char**) if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) done = true; } + + // Start the ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplSDL2_NewFrame(window); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". diff --git a/examples/sdl_vulkan_example/main.cpp b/examples/sdl_vulkan_example/main.cpp index 50cdb102..a88c9c1b 100644 --- a/examples/sdl_vulkan_example/main.cpp +++ b/examples/sdl_vulkan_example/main.cpp @@ -411,6 +411,7 @@ int main(int, char**) bool done = false; while (!done) { + // Poll and handle events (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. @@ -424,8 +425,11 @@ int main(int, char**) if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED && event.window.windowID == SDL_GetWindowID(window)) ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, (int)event.window.data1, (int)event.window.data2); } + + // Start the ImGui frame ImGui_ImplVulkan_NewFrame(); ImGui_ImplSDL2_NewFrame(window); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". diff --git a/examples/vulkan_example/main.cpp b/examples/vulkan_example/main.cpp index 2b39fa83..13588c46 100644 --- a/examples/vulkan_example/main.cpp +++ b/examples/vulkan_example/main.cpp @@ -423,20 +423,22 @@ int main(int, char**) // Main loop while (!glfwWindowShouldClose(window)) { + // Poll and handle events (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. glfwPollEvents(); - if (g_ResizeWanted) { ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, g_ResizeWidth, g_ResizeHeight); g_ResizeWanted = false; } + // Start the ImGui frame ImGui_ImplVulkan_NewFrame(); ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); // 1. Show a simple window. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". diff --git a/imgui.cpp b/imgui.cpp index 28af3212..0f7edbe6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -264,6 +264,8 @@ You can read releases logs https://github.com/ocornut/imgui/releases for more details. (Viewport Branch) + - 2018/XX/XX (1.XX) - examples: the examples imgui_impl_xxx files have been split to separate platform (Win32, Glfw, SDL2, etc.) from renderer (DX11, OpenGL, Vulkan, etc.) + when adopting new bindings follow the code in examples/ to know which functions to call. - 2018/XX/XX (1.XX) - when multi-viewports are enabled, all positions will be in your natural OS coordinates space. It means that: - reference to hard-coded positions such as in SetNextWindowPos(ImVec2(0,0)) are probably not what you want anymore. you may use GetMainViewport()->Pos to offset hard-coded positions, e.g. SetNextWindowPos(GetMainViewport()->Pos)