This topic has been discussed before, but here are my experiences trying to get OpenGL working with C#.
First thing I did was to figure out how to use the Win32 API functions in C#. It was easy enough, but you have to basically import every function you use, similar to the way you would in VB.
So I started out importing the Set/Describe/ChoosePixelFormat functions as well as the wgl functions wglCreateContext and wglMakeCurrent.
Then I tried to use them. I basically took some existing C++ code to initialize an OpenGL window, plopped it in, and modified a few lines of code so that it was calling my C# functions.
Everything worked fine right up until wglCreateContext. That would always fail. I tried pulling up the memory window, and compared the memory my PIXELFORMATDESCRIPTOR struct to make sure the C# struct wasn’t adding any sort of extra padding, but it was identical to my C++ PIXELFORMATDESCRIPTOR struct.
I tried doing a GetPixelFormat call right after the SetPixelFormat only to find out that the Get was NOT what I had just Set! I tried that in my C++ app just to make sure it wasn’t an API thing, but the C++ app returned what was expected. So, it appeared that SetPixelFormat was failing, but reporting back that it was succesful.
By now I was frustrated so I took a look at the source code for a .Net OpenGL library someone else had done. What I found out was that that library was actually calling out to a separate C++ DLL that did all the Pixelformat work!
My only conclusion is that there are some problems caused in the marshalling of the managed to unmanaged code.
So in conclusion, the best way to use OpenGL in .Net is to use a third party library. I believe it was called csgl on Sourceforge.net. And now when I go to look at that, it appears that it’s not quite what I was hoping for. All the example code seems to attempt to use something like a Document/View architecture. If there are nice simple classes to be used outside of that, I haven’t had the time to figure them out yet.
[This message has been edited by Deiussum (edited 10-18-2002).]