- Install the Tao Framework, download it here.
- In VisualStudio.net Toolbox, add a new Tab and rename it with a meaningful caption:
- In the new Tab category, right click”Choose Items”:
- Browse to the control “SimpleOpenGLControl”
- Drag the control onto the Windows Form designer, this will automatically add two reference assemblies to the project:
- Using the object browser to have a closer look at the control, it shows that the class hierarchy is:
public class SimpleOpenGlControl : System.Windows.Forms.UserControl , Member of Tao.Platform.Windows
i.e. a user control. The class provides several virtual functions, which, you can inherit from it and override in order to perfom OpenGL renderings in your project.
- Now, compile the program and there will be no error, however, if you run it, you will see a messagebox. And to trouble shoot this, you need to add a few code lines.
- Add the following code first
- And then, in the Form.Load event handler add the code below and rerun it, now it works!
glControl.InitializeContexts(); //Assuming that you have named the control “glControl”;
- Now to render something, you can handle the OnPaint event of the control:
- Type the demo code to see the results:
With this, all your previous C++ OpenGL codes can be immigrated to C# with ease.