Author Topic: Opengl in c# ?  (Read 7202 times)

0 Members and 1 Guest are viewing this topic.

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Opengl in c# ?
« 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.


Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Opengl in c# ?
« Reply #1 on: March 11, 2009 »
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, 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/

Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Opengl in c# ?
« Reply #2 on: March 11, 2009 »
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 :)

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Opengl in c# ?
« Reply #3 on: March 14, 2009 »
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
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Opengl in c# ?
« Reply #4 on: March 14, 2009 »
Hi Jim,

Would that be what this sort of code is doing ?

Code: [Select]
[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

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Opengl in c# ?
« Reply #5 on: March 15, 2009 »
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
Challenge Trophies Won:

Offline Allosentient

  • ZX 81
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
Re: Opengl in c# ?
« Reply #6 on: March 26, 2009 »
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.