Skip to main content
GameDev.net gamedev.net
🔒 Locked

OGL with C#

Started by amethyste Feb 26, 2009 at 2:24 AM 3 replies 2.2k views
Original Post
amethyste
amethyste
Hi, I works with C++/GLUT/OGL Now I developp with C# and I want continued my development with this language. OGL works fine with C# ? What is the performance of the binding ? thanks
iliak
iliak
Hi

It works perfectly. Look at the Tao Framework for example.
For what I know, only function calls uses PInvoke not OpenGL commands.
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
Fiddler
Fiddler
Indeed, it works perfectly. I'm obviously biased, but I'd suggest OpenTK over Tao - both share much of their code, but OpenTK follows .Net conventions and is much easier to use.

The performance of the binding is very good, no problems there. The real bottleneck is math, if you are going to do complicated stuff like physics. Even that can be worked around, however, so it's not a show stopper.
[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]
amethyste
amethyste
OpenGL isn't think in oriented Object.

Tao or OpenTK is oriented object ?

There are benchmark between this api and other language ? (C++, JOGL, ...)

What is the advantage of this technologies against XNA or SlimDX for a windows only project ?

Thanks
Fiddler
Fiddler
The bindings in Tao and OpenTK are not object oriented. Let me give you a simple example in both libraries.

OpenTK:
using OpenTK.Graphics;[...]public void Render(){    GL.MatrixMode(MatrixMode.Projection);    GL.LoadIdentity();    GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);    GL.MatrixMode(MatrixMode.Modelview);    GL.LoadIdentity();    GL.Clear(ClearBufferMask.ColorBufferBit);    GL.Begin(BeginMode.Triangles);    GL.Color3(Color.MidnightBlue);    GL.Vertex2(-1.0f, 1.0f);    GL.Color3(Color.SpringGreen);    GL.Vertex2(0.0f, -1.0f);    GL.Color3(Color.Ivory);    GL.Vertex2(1.0f, 1.0f);    GL.End();}


Tao:
using Tao.OpenGl;[...]public void Render(){    Gl.glMatrixMode(Gl.GL_PROJECTION);    Gl.glLoadIdentity();    Gl.glOrtho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);    Gl.glMatrixMode(Gl.GL_MODELVIEW);    Gl.glLoadIdentity();    Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);    Gl.glBegin(Gl.GL_TRIANGLES);    Gl.glColor3(0, 0, 0.3f);    Gl.glVertex2(-1.0f, 1.0f);    Gl.glColor3(0.5f, 0.7f, 0.1f);    Gl.glVertex2(0.0f, -1.0f);    Gl.glColor3(0.9f, 0.9f, 0.85f));    Gl.glVertex2(1.0f, 1.0f);    Gl.glEnd();}


As you can see, OpenTK is a little cleaner and the strongly-typed enums make it easier to use. Both are equivalent to using plain C.

Benchmarks show that pinvoked functions are ~20ns slower on .Net and ~8ns slower on Mono (measured on a 2.6GHz Core2 processor running in x64 mode.) However, keep in mind that benchmarks are relatively meaningless at this low level, as the bindings themselves are *not* a bottleneck. The real bottlenecks lie on the GPU, your math code and your memory management & data structures.

Edit:

What is the advantage of Tao/OpenTK compared to SlimDX/XNA? You can write your game on Windows and have the same executable run on Linux and Mac OS X, without even recompiling - a single exe for all platforms!

Apart from this, the first use OpenGL and the latter use DirectX - which API do you prefer?
[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.