Introduction

This sample showcases the multi-threading capabilities of the GameWindow. It simulates particle movement that interacts with the window bounds and reacts to window Resize and Move events.

Controls

Move or resize the window with your mouse.
Press F11 to toggle between fullscreen and windowed modes.
Press Esc to exit.

Implementation

This sample spawns a background thread to handle OpenGL rendering. The main thread reacts to IGameWindow events as usual but contains no OpenGL commands. Instead, it notifies the background thread of the necessary IGameWindow state changes (e.g. Resize events) and lets it handle them˙.

1. The constructor hooks IGameWindow events using anonymous delegates. These hooks handle keyboard input, resize and move events. In the case of resize and move events, they set flags to notify the render thread of the state changes.

2. The Load event releases the OpenGL context from the main thread (Context.MakeCurrent(null)) and spawns the background render thread.

3. The background render thread make the OpenGL context current (MakeCurrent()) and then enters a continuous game loop until exit. This loop handles logic updates, OpenGL rendering and the necessary timing tasks.

4. The Unload event notifies the background thread that it should shut down and waits until it does.