GUI on secondary window: docs misleading


My application splits the main output into one window and a “settings” window into another.

The documentation for IMGuiService states:

selectWindow(): Explicitly set the window that is used for drawing the GUI elements. When no window is specified the system uses the primary window to draw GUI elements. Only set the window on init() of your application.

This seems to be incorrect. Since you have to call mGuiService->draw() yourself anway, this doesn’t make much sense.

Without calling selectWindow anywhere at all, you can draw the GUI to another window simply by calling mGuiService->draw() after making another window active (in my case, mSettingsWindow->makeActive()).

What selectWindow does seem to do, however, is determine which Window receives mouse inputs for the GUI. Failure to do this means that the GUI draws just fine, but cannot be controlled.

Should the docs be updated, or am I misunderstanding the situation?



selectWindow() is used to associate a specific window with a GUI. But you always have to call draw() to render the gui. At the moment NAP only supports a GUI for one window, by default the main window. This can be either window 1 or 2, depending on the render service and order of initialization.

To allow the user to explicitly set the window to associate with the GUI you must use selectWindow(), if you don’t, the GUI can only be drawn to the primary window, which in your case could be the one you are currently rendering to. That draw() works on any windows on OSX has to do with vendor specific implementations of OpenGL. Which makes it impossible to get correctly functioning cross-platform behaviour. It is therefore important to tell the system which window receives the GUI calls on init() and draw to it on render.

I know this is confusing and I’d rather not have that call in there but OpenGL context specific state / storage makes it difficult to do this otherwise. It’s recommended to call selectWindow() on init, see multi-window demo for an example.

Without the select window, the gui potentially fails to draw to a specific window if you haven’t selected it to be the main GUI window.

Cheers Coen


This is probably true, as you have explained, but I still think it’s very important for the docs to mention (perhaps in addition) that if you don’t call this, you will not be able to control the GUI, even if it is drawn properly in the window you expected.


not probably, it is true ;). I will add your suggestion to the docs regarding control.