Which Thread For Handling OpenGL's Window?

Hi Folks:

I want a nice animated splash screen for my Windows application.

The opening screen is a menu bar over the window where a 3D model created with Blender slowly rotates. This screen will be open, in the background, while the application runs.

The Simple Question:

Right now the user’s only interaction with the application is with the menu bar, and menus that drop down over the model’s window.

I’m not shy about spawning a thread, but there’s a general rule to keep all GUI stuff in one thread.

Would you consider the window with the rotating model part of the GUI? Or can I safely have a game loop in it’s own thread rotating the model while the main thread handles the “real” GUI?

The Complicated Question

What if I want to allow the user to fly around the splash screen with WASD keys and the mouse?

Flying around the model would be an amusing distraction, the business of the application is in the many dialogs accessible through the menus.

While they were flying around the model I’d lock the mouse to OpenGL’s window, allowing them to get back to the application with an escape key.

Could I safely run this through the game loop in another thread?


See glfw documentation on thread safety: http://www.glfw.org/docs/latest/intro.html#thread_safety

Basically you can render from any thread, but window event processing must happen on main thread due to limitations of some of platforms. On some platforms it will work fine if you consume events on non-main thread, but on some platforms it won’t work at all. So if your use case of glfw is to maintain cross-platform compatibility, process window events only on main thread.

1 Like