-
-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No redraw during OS window resize in demo #3672
Comments
That has nothing to do with Dear ImGui and fully depends on your backend. Note: |
As answered this is generally the "default" behavior under Windows as resizing via OS borders/decoration puts Windows into a modal/blocking loop, so it's not really specific to Dear ImGui. Any GLFW+GL application will give you same result by default. (Note that in multi-viewports mode resizing Dear ImGui windows via the Dear ImGui borders/decorations doesn't exhibit the problem, since it doesn't go through Windows modal/blocking loop). There are variety of solutions available elsewhere, at low-level I think generally it seems to involve reacting on WM_TIMER, e.g. At GLFW level it seems like you are supposed to call It's a little outside the scope of our examples to do work (ideally we would do but in practice what we would do in the examples application may not match what you would/can do in your real app). |
Since this is frequently being asked practically everywhere (a little bit here but also much more in SDL/GLFW/Gamedev communities), I would ideally like us to make our examples apps demonstrate the dynamic resizing. I think step 1 is to do it for major examples (at least 1 example for each of Win32, SDL and GLFW) and then either we decide this is mergeable, either we write a definitive wiki page with instructions of how to change your app to support this.
Extra references:
|
There are other ways to achieve this at least on X11 and Wayland (not sure about Windows), but are even less trivial. I guess a macro that captures the function defined by the user and assigns it to some function object could be a compromise between readability while still yielding a reusable function: #define IMGUI_MAIN_FUNC(...) imgui_main_func /* some global variable for a function object */ = [&]() { __VA_ARGS__ };
// ...
int main() {
setup();
ImGuiIO& io = ImGui::GetIO();
static float f = 0.0f;
static int counter = 0;
while (!windowShouldClose()) {
preFrame();
IMGUI_MAIN_FUNC(
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::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 / io.Framerate, io.Framerate);
ImGui::End();
)
postFrame();
}
} At least for examples. Afterall this would interfere with C interoperability if the function needs to capture state. But this gives you a function object that could be used in whatever dynamic resizing mechanism you use while keeping the code and state local to the main function. |
Hi @Folling long time no see :) That's the trick we use for our Emscripten wrapper: Basically I think the core problem is actually too complex to solve perfectly-for-every-use-case and simply in a way that we would dare adding them to our examples, but I think we should nevertheless gather the info and provide it in a centralized place, so at least people know can know what to copy if they want it, and can report improvements. (PS: Updated my comment above with many links.) |
Indeed it has been :) FWIW: The alternative approach on X11 that I used a while back involves multithreading and conditional variables where you have one thread listen to events and notify the main thread that a new render is required whenever an adequate event is posted by the X window manager. |
If we provide a tutorial for implementing this, I have zero issue making the tutorial use a separate function for the frame. Question was only about providing this in our example, which I think may be too complicated for other reasons |
For anyone else that is stumbling into this issue with this problem and was hoping for a quick fix, I'll leave these notes on what I did. (It was not a quick fix.) I am using pure Win32, not GLFW. I don't have a fully updated example unfortunately because my use-case is only roughly inspired by the example. One solution to this problem is to decouple your rendering from the windows message pump. Here is the general roadmap for this approach:
I've put the moral equivalent of my changes to the backend implementation file here. Note that the If you are using SDL, there is also a solution available now (at least for Windows), as documented in this GitHub issue conversation. |
What worked for me in GLFW is only having glfwPollEvents() on the main thread, and the update and rendering in another thread (without polling events). The drawback is that multiple viewports don't work (they don't receive events, unless I add another glfwPollEvents(), but this breaks other things, also not recommended by GLFW). I think it's worth the compromise of not using viewports in my case, I can still use the docking features, and it is so beautiful to see the window being redrawn while resizing hahah. I hope this will work in the long run, or at least until the PR @ocornut mentioned for GLFW is merged (it's been more than 4 years, yikes) |
Version: 1.79
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: Visual Studio 2019
Operating System: Windows 10
When resizing the OS window there is no redraw in the demo applications, I think that it will be nice if this case was handled because I saw this issue in some other applications made using Dear ImGUI like tracy profiler or ImHex.
As end user when I see an application that stop rendering during the window resize I fell like if there is a performance issue here.
The text was updated successfully, but these errors were encountered: