Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: TinDragon on March 10, 2009
-
Can anyone tell me if its possible to use opengl in c# without any external dll's or overly complex frameworks? I would like to be able to use it to make some tools/editors, its probably easy but I am rather new to c#. Should point out I am using VS c# 2008 express just incase there's a difference with some ide's.
-
I've read somewhere that you can not link directly to opengl with C# but I'm not sure.
If your target is to make simple tools/editors in C#, I see no problems to include a little DLL, like SharpGL (http://www.sharpgl.com/), accompanying your project. It's free, clean and it won't bloat your project.
http://www.codeproject.com/KB/openGL/sharpgl.aspx
http://www.sharpgl.com/
-
Will take a look at that one rbz. I actually took a look at the NeHe c# basecode, from the files there they seem to have set up some external calls to the opengl dll's whic might be what there doing with sharpgl only they wrapped it in a dll rather than several files you need to include. But i like the way the sharpgl one looks like it adds a simple opengl item to the visual form designer, that should make it easy to create ogl stuff :)
-
It's possible to access any of the standard Windows API stuff, as well as OpenGL, from C# as long as you have the correct voodoo. You need to write a line to import each function, and that will manage the transition from managed C# code to native Win32 and back again.
Let me know if you want help with that.
Jim
-
Hi Jim,
Would that be what this sort of code is doing ?
[DllImport(GL_DLL,EntryPoint ="glAccum")]
public static extern void glAccum(uint op,float valuex);
this is a small snippet from the nehe c# basecode which has 2 or 3 files that have loads of lines like that for alot of the opengl commands as well as lots of defined constants. If I understand what its doing, its providing an entry point to the opengl function in the dll so that within my c# code I could use them much like i would in c/c++ or any other language.
If you want to explain how you would come up with this sort of thing then I am sure others as well as myself would be interested, I assume the basic prinicle can be used with lots of .dll's
Cheers
Jon
-
That's exactly what you need :)
If you look in gl.h that comes with the Platform SDK or from opengl.org you can see what the parameters should look like - it's pretty much a cut and paste job.
You need one line for each function you want to call. I'd have a look around if I were you, someone is bound to have converted the whole API by now.
Jim
-
I've been very happy with this:
http://www.opentk.com/
Avoid Tao Framework unless you are an oldschool OpenGL purist who doesn't have a problem with using the procedural-based syntax.