Using OpenGL in C# (Tao.Framework)

01 Dec

  • Install the Tao Framework, download it here.
  • In 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:
  • Tao_addto_toolbox2.png
  • 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.Tao_addto_toolbox3.png
  • 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.
  • Tao4.png
  • Add the following code first
    using Tao.OpenGl;
    using Tao.Platform.Windows;
  • 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.


Posted by on December 1, 2008 in CAD, Dotnet/C#


30 responses to “Using OpenGL in C# (Tao.Framework)

  1. gaHcep

    December 10, 2008 at 8:26 am

    Thanks, tutorial is just in time 🙂

  2. saintist

    January 9, 2009 at 2:59 am

    Very good sample, senk

  3. Rajeev Lochan

    February 15, 2010 at 1:09 pm

    Thanks for the lovely tutorial on getting started with Tao Framework.


  4. Dan

    June 4, 2010 at 11:24 pm

    I’ve followed this to the teeth and sadly it does not work, it only shows a white box where the “glControl” is located. I am using VS08, anything I’m missing?

  5. xinyustudio

    June 10, 2010 at 1:56 am

    If you could offer more details of the errors, I can help troubleshoot this. Check below:
    +If you have coded some OpenGL actions;
    +What OS are you using? English or other international languages?
    +Can you successfully draw sth using C++?

  6. xinyustudio

    August 10, 2010 at 2:45 am

    Update: the download link of Tao framework, previously no longer valid, is now corrected. You can directly download it using the link provided now.

  7. 10gler

    September 24, 2010 at 7:52 pm


    You ilustrate than OnPaint event should handled to call render method. I have a question, when OnPaint is invoked by the control? I would like perform same animation so the render should be invoked (scene refreshed) in any possible time (very fast).
    I added same thread to my program that call rener method. But somethimes I have collision (OnPain invoke render and my thread also).

    Best regards

  8. xinyustudio

    September 24, 2010 at 8:14 pm

    I suppose the OnPaint event of the control calls OpenGL funcions,instead of the opposite direction. Moreover, I am not very clear about your problem. You may refine your problem, and I will try to help.

  9. 10gler

    September 25, 2010 at 12:56 am

    Ok, I try to explain main problem.
    In your example the triangle position is static. What sould be done rotate your triangle? (for example).
    I put in my rendeering class variable angle and call a glRotatef(angle++, 1, 0, 0) before draw triangle but nothing happen (possiotion of triangle is static). So I debuged program and noticed that onpaint event is called “from time to time” maybe even ones.

  10. 10gler

    September 25, 2010 at 1:15 am

    In the and of onpaint event I call glControl.Draw(); method – now it works perfect and no extra rendering thred needed.

    Is it correct way?

  11. xinyustudio

    September 26, 2010 at 3:36 pm

    You may simply try calling refresh() method of the control? I guess it may work for your purpose.

  12. 10gler

    October 12, 2010 at 5:12 am


    Is it possible to get source code of this control?

  13. xinyustudio

    October 12, 2010 at 8:49 pm

  14. Mohammed Younus Ahmed

    November 26, 2010 at 1:58 am

    It will be better if some video is published in this regard. I am able to add the Tao Framework to Vs2010 but it never come in the list if .net components . Please help

  15. syed sheheryar

    July 7, 2011 at 6:42 am

    Now waht to do IF I wanted to save the object craeted in a jpg file or image file .

  16. kuzziunns

    January 11, 2012 at 5:32 am

    Thanx .y

  17. Mahantesh

    April 11, 2012 at 1:24 pm

    I tried to add simpleopenglcontrol into my tool box but couldn’t find .so is there any mistake in installing it or any other problem?

  18. Apoca

    March 18, 2013 at 2:05 am

    Use in Microsoft Visual Studio 2010 Ultimate!??

  19. xinyustudio

    March 18, 2013 at 10:02 am

    VS2010, yes.

  20. Apoca

    March 20, 2013 at 9:34 am

    This plugin works with Windows Phone Game (4.0)!?

  21. Mary Hawkins

    March 4, 2014 at 11:33 am

    I am having this bug while trying to compile my project:
    Error 1 The name ‘winOG’ does not exist in the current context

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Tao.OpenGl;
    using Tao.FreeGlut;
    using Tao.Platform.Windows;

    namespace Lab1_OpenGL
    public partial class Form1 : Form
    PointF[] points;
    public Form1()
    private void loadObject()
    points = new PointF[5];
    points[0].X = 5F; points[0].Y = 3.5F;
    points[1].X = 5F; points[1].Y = 5.5F;
    points[2].X = 4F; points[2].Y = 4.5F;
    points[3].X = 6F; points[3].Y = 4.5F;
    points[4].X = 5F; points[4].Y = 5.5F;
    private void drawObject()
    for (int i = 0; i < points.Length; i++)
    Gl.glVertex2f(points[i].X, points[i].Y);
    private void Form1_Load(object sender, EventArgs e)
    Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_DOUBLE);

    Glu.gluOrtho2D(3, 6, 3, 6);
    Gl.glClearColor(150, 120, 235, 1);

    Gl.glColor3f(0, 255, 0);


    can anyone help with this issue?
    google knows nothing about winog… OMG…. ))

  22. daniel

    March 13, 2014 at 4:58 am

    Thanks a lot!!!

  23. ahcene

    March 31, 2014 at 7:46 am

    thank you

  24. Ricardo

    June 9, 2014 at 5:14 am

    I absolutely love your blog.. Very nice colors & theme. Did
    you create this amazing site yourself? Please reply back as
    I’m attempting to create my own blog and want to find out where you got this from or just what the theme is called.
    Many thanks!

  25. xinyustudio

    June 9, 2014 at 7:59 am

    No, both wordpress host and the theme are free!

  26. Steven

    April 5, 2016 at 9:11 pm

    The pictures are broken 😦
    Would have been cool if you reupload it


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: