Using OpenGl with C#? [closed]
Is there free OpenGL support libraries for C#? If so, which one do I use and where do I find sample projects?
Does C# provide classes for OpenGL?
Solution 1:
OpenTK is an improvement over the Tao API, as it uses idiomatic C# style with overloading, strongly-typed enums, exceptions, and standard .NET types:
GL.Begin(BeginMode.Points);
GL.Color3(Color.Yellow);
GL.Vertex3(Vector3.Up);
as opposed to Tao which merely mirrors the C API:
Gl.glBegin(Gl.GL_POINTS); // double "gl" prefix
Gl.glColor3ub(255, 255, 0); // have to pass RGB values as separate args
Gl.glVertex3f(0, 1, 0); // explicit "f" qualifier
This makes for harder porting but is incredibly nice to use.
As a bonus it provides font rendering, texture loading, input handling, audio, math...
Update 18th January 2016: Today the OpenTK maintainer has stepped away from the project, leaving its future uncertain. The forums are filled with spam. The maintainer recommends moving to MonoGame or SDL2#.
Update 30th June 2020: OpenTK has had new maintainers for a while now and has an active discord community. So the previous recommendation of using another library isn't necessarily true.
Solution 2:
I think what @korona meant was since it's just a C API, you can consume it from C# directly with a heck of a lot of typing like this:
[DllImport("opengl32")]
public static extern void glVertex3f(float x, float y, float z);
You unfortunately would need to do this for every single OpenGL function you call, and is basically what Tao has done for you.