Multi-window & ImGui



For the app we’re building we’ve reached the point where we want to separate our 3D drawing from our GUI (built using ImGui). We want to add a second window, and have ImGui use this second window, while the old/primary window will be used for 3D drawing.

How do we tell ImGui to use the second window? :slight_smile:


ImGui secound window combination


This is already possible but with 1 restriction, the GUI needs to be rendered to the primary window. You can render the other default nap objects to any window. Stijn has already implemented this for a project he worked on. You can also take a look at the multiwindow demo, this renderes a gui to the primary window.


Okay, got this working.

For those interested… to make the ImGui ui use the entire window, I used the following code,

ImGui::SetNextWindowSize(ImVec2(screenSize[0], screenSize[1]));
ImGui::Begin(“Monitor”, nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);




So this makes both windows 1 IMGUI canvas? Am I correct?

Would you still prefer to setup a GUI for each window individually?


It makes ImGui use the entire primary window. It doesn’t somehow combine both windows. It just removes ImGui’s own window border etc. Since ImGui now has its own dedicated window, we don’t need ImGui to imitate a window anymore.


Ah cool!

I have just submitted a bunch of changes regarding IMGUI and NAP. Most importantly the user can now select which window to use to display and interact with the GUI. You can select the window by calling:

IMGuiService::selectWindow(nap::ResourcePtr<RenderWindow> window);

It is also possible to change the window at runtime, although probably not something you want to do frequently. Best to select the window when you initialize your application.

Next to this change I reworked the GUI code and got rid of the native SDL implementation that shipped with IMGUI. This allowed me to limit the amount of cross library calls and remove the need for a global IMGUI state, which I always hated. All IMGUI related functionality is now handled by the IMGUI service. I can now work on drawing a GUI on all windows.