RSS

Using OpenGL in C# (Tao.Framework)

01 Dec

  • 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”:
    Tao_addto_toolbox0.png
  • 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.

 
18 Comments

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

 

18 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.

    Rajeev

     
  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

    Dan,
    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

    Hi,

    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

    Hi!

    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?

     

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

 
Follow

Get every new post delivered to your Inbox.