Multiple windows and interop with ImGui

Hi there, I’m trying to add a second “preview” window to my app. The main window has an ImGui UI in it, and when I create a second window (which just displays a texture/FBO), I start to get problems. I think this is because the ImGui context gets mixed up between the two windows.

I see the Options flag autoRender, which prevents ImGui::NewFrame() and ImGui::Render() from being called automatically. So I figured I could insert them at the appropriate places, for my main window. However, it seems the Cinder implementation does some extra stuff, which is probably important to co-exist with Cinder (the default implementation calls ImGui_ImplCinder_NewFrameGuard() and ImGui_ImplCinder_PostDraw(), which are hidden (static) functions in CinderImGui.cpp, so I can’t directly call them where I need to. They do call ImGui::NewFrame() and ImGui::Render(), but also do other things…

Any tips on the right way to do this? If necessary, I can try to extract out a minimal repro example, but maybe someone has run into this before.


P.S. Things “mostly” seem to be working fine when I open the new window (leaving autoRender at the default value of true), but definitely get screwed up when I move the second preview window to a different display. Also, when I close the second window it crashes, because the ImGui code is trying to access an invalid/destroyed Window.

Looking at this more, I think the Cinder ImGui code looks mostly right…the window you setup ImGui with is the one that gets the postDraw signal and all the others, for example. The problem is with update – if you have multiple Windows, it seems indeterministic which one will be current when it’s called… And so, aha! the problem seems to be in the use of app::getWindow()->toPixels() rather than using the proper window that was registered for use with ImGui. I’ll try giving this a fix…should be pretty simple.

Fixed here:

Fix glitches when using ImGui in an app with multiple windows by totalgee · Pull Request #2242 · cinder/Cinder (

The other thing I needed to do (besides the above fix) was move my ImGui “layout” code into the draw() callback for my main window, not in the update() function, where I had it previously.

UPDATE: Actually, with my fix there is no need to do that, it seems fine to call ImGui functions to build your UI from update(), even when the current window happens not to be the ImGui one.