todd's picture

Raw OpenGL bindings


I've been enjoying playing with OpenTK: the enum's for input parameters are particularly sweet.

HOWEVER... I am trying to port some moderately gnarly Java/JOGL code into C# with minimal changes. JOGL exposes a fairly raw-looking interface: input parameters take the form GL.GL_CONSTANT_NAME instead of using cool enum's. Is there some way to gain access to the raw OpenGL bindings while using OpenTK? Is there a different, more basic library I should consider for OpenGL access?

It looks like Tao might do the trick... but their website's down and Wikipedia reports their last update as being two years ago!

Thanks for any advice.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kvark's picture

Did you look at OpenTK.Graphics.OpenGL.All ?

todd's picture

Nice. Thanks, kvark.

Is there a place where I can make the OpenGL calls and pass in the entries from OpenGL.All?

E.g., instead of "GL.MatrixMode(MatrixMode.Projection)" I'd prefer to use "GL.MatrixMode(All.Projection)". Picky, I know.

kvark's picture

The final word is up to Fiddler, but I don't see it's possible to call standard OpenTK methods with raw enum binding.
You'll need to cast it to proper enums all the way...

the Fiddler's picture

OpenTK is using strongly-typed enums by design, in fact this is one of its main features.

What you can is reference OpenTK.Compatibilty.dll and use the Tao.OpenGl namespace, which uses raw constants (Gl.GL_NAMED_CONSTANT). Chances are you will still need to port some things over from Java, but the process should be much less painful.

Having ported Tao applications to OpenTK before, I can say that this is not easy - which is why OpenTK now includes an intact copy of the Tao.OpenGl namespace.

todd's picture

Fabulous. That's exactly what I was looking for.

Yeah, I knew the enum's were one of the primary features of OpenTK. And they're pretty nice when writing your own stuff from scratch. But the Tao bindings are making my porting project much more pleasant.

Basically, at the top of each file that uses OpenGL, I include:

using GL = Tao.OpenGl.Gl;

And the real hackish beauty comes when the code I'm porting goes to set a color based on a C# Color. Instead of extracting values, converting them to floats, and worrying about the order, I just call OpenTK:


Thank you!

For what it's worth, a colleague and I ended up porting javax.vecmath, too. vecmath and OpenTK seem to hold their matrices a little differently: in the end I decided it was simplest to give my legacy code access to the math library it'd been using all along. vecmath is GPL2 + classpath (thank you, Sun!), so I'd be happy to pass along my (rather wooden and almost completely untested) translation.