Introduction

This sample demonstrates the GLControl, a powerful, easy-to-use WinForms Control that supports OpenGL rendering. It displays a Form that consists of a GLControl and three buttons that change the OpenGL clear color.

The GLControl is suitable to rich, event-based GUIs. It is cross-platform and integrates well with WinForms applications but can also be used with WPF applications using a WindowsFormsHost control.

While it is possible to implement continuous rendering with GLControl (see next sample), applications that require continuous rendering can achieve better performance with GameWindow.

Controls

Click on the buttons to change the background color for the GLControl.
Press Esc or click the close button to exit.

Implementation

This sample was created using the WinForms designer in Visual Studio. As such, the code follows the conventions of this designer.

1. The constructor calls InitializeComponents(). This method is generated by the designer and initializes the Form, GLControl and Buttons.

2. The glControl1_Paint event handler is called whenever GLControl needs to be repainted. A typical Paint handler will begin by calling GL.Clear() and end with a call to GLControl.SwapBuffers().

3. The various *Button_Click event handlers change the OpenGL clear color and invalidate the GLControl. The Invalidate() method raises the GLControl Paint event and ensures the updated clear color becomes visible immediately.