- 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
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.
Thanks, tutorial is just in time 🙂
Very good sample, senk
Thanks for the lovely tutorial on getting started with Tao Framework.
Rajeev
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?
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++?
Update: the download link of Tao framework, previously no longer valid, is now corrected. You can directly download it using the link provided now.
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
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.
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.
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?
You may simply try calling refresh() method of the control? I guess it may work for your purpose.
Hi!
Is it possible to get source code of this control?
http://sourceforge.net/projects/taoframework/files/The%20Tao%20Framework/2.1.0/taoframework-2.1.0.zip/download
unzip and go to folder \source\
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
Pingback: 2010 in review « Xinyustudio
Now waht to do IF I wanted to save the object craeted in a jpg file or image file .
Thanx .y
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?
Use in Microsoft Visual Studio 2010 Ultimate!??
VS2010, yes.
This plugin works with Windows Phone Game (4.0)!?
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()
{
InitializeComponent();
winOG.InitializeContexts();
}
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()
{
Gl.glBegin(Gl.GL_LINE_LOOP);
for (int i = 0; i < points.Length; i++)
Gl.glVertex2f(points[i].X, points[i].Y);
Gl.glEnd();
}
private void Form1_Load(object sender, EventArgs e)
{
Glut.glutInit();
Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_DOUBLE);
Gl.glEnable(Gl.GL_DEPTH_TEST);
Glu.gluOrtho2D(3, 6, 3, 6);
Gl.glClearColor(150, 120, 235, 1);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glColor3f(0, 255, 0);
loadObject();
drawObject();
Gl.glFlush();
winOG.Invalidate();
}
}
}
can anyone help with this issue?
google knows nothing about winog… OMG…. ))
Thanks a lot!!!
thank you
Pingback: Recent hot posts | Xinyustudio
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!
No, both wordpress host and the theme are free!
Pingback: How to: Using OpenGl with C#? | SevenNet
Pingback: Using OpenGl with C#? [closed] | ASK AND ANSWER
The pictures are broken 😦
Would have been cool if you reupload it