PDA

View Full Version : .NET OpenGL



rwilliams
02-20-2004, 08:48 PM
Is there a way to implement OpenGL in a
Windows Forms Application using VC++ .Net?
http://www.opengl.org/discussion_boards/ubb/confused.gif

Thanks in advance

dorbie
02-21-2004, 12:31 AM
Dunno what you mean by Windows Forms Application but I use .NET and OpenGL.

Whatever you use you can get a context from an HDC (be calling GetDC) and a call to ChoosePixelFormat.

The rest is up to you. You could derive a class from something you can get an HDC from.

jwatte
02-21-2004, 07:33 AM
Windows Forms is the GUI framework that comes with .NET.

Assuming you can get a DC out of a Forms control, you should be able to make it work.

I think the best way to integrate non-managed APIs (such as OpenGL) with .NET when there is no managed wrapper already, is to use Managed C++ to write a wrapper; it's fairly easy to mingle managed and unmanaged heap objects and safe and unsafe pointers in that environment. Then use this C++ wrapper from the .NET language of your choice.

SirKnight
02-21-2004, 09:11 AM
You can get the DC by doing something like this:

Graphics g = this->CreateGraphics();
IntPtr hDC = g.GetHdc();

Now you have your DC. The 'this' is refering to your Form of your application. There are other classes that have the CreateGraphics function like the Control class, etc. In order to draw to anything yourself, you must get a Graphics object, which is just a drawing surface. From here you can use any of the GDI+ drawing functions or get the DC and go from there, with say opengl or something.

You will also have to do what jwatte said about making a wrapper with the mixing of managed and unmanaged code since there is no managed OpenGL assembly.


-SirKnight

dorbie
02-21-2004, 11:13 AM
Hmm... so MFC code is old hat now, guess I'd better brush up on the .NET GUI stuff.

SirKnight
02-21-2004, 01:18 PM
Yeah this is going more and more off topic but using .NET for GUIs makes writing GUI apps very easy. Using .NET makes windows programming a breeze. The downside is if someone wants to run your program, they have to have the .NET framework installed. Once Longhorn arrives, that wont be a problem for users of that OS though. I still think wxWindows (now wxWidgets) is a very good GUI SDK which now supports .NET I think. Plus its cross platform. http://www.opengl.org/discussion_boards/ubb/biggrin.gif


-SirKnight

Ffelagund
02-21-2004, 02:19 PM
Yes, you can do it. I have done it with the Shader Designer.
The way is to get the HWND of the Window/control into you want render the opengl stuff.
You only need this line:
HWND hWnd = (HWND)mydotNetWindow->get_Handle().ToPointer();
with this you can call win32 functions like getDC

rwilliams
02-21-2004, 04:57 PM
First, thanks so much for trying to help me out and I apologize for asking such a generalized question. Next, I have linked with opengl32.lib and glu32.lib. Also I have #include <gl/gl.h> and <gl/glu.h> in the main .cpp file.

Whenever i try to build the project I get a rather long list of errors. I have pasted a few of them here...

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1152): error C2144: syntax error : 'void' should be preceded by ';'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1152): error C2501: 'WINGDIAPI' : missing storage-class or type specifiers

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1152): error C2146: syntax error : missing ';' before identifier 'glAccum'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1152): error C2182: 'APIENTRY' : illegal use of type 'void'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1153): error C2144: syntax error : 'void' should be preceded by ';'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1153): error C2501: 'WINGDIAPI' : missing storage-class or type specifiers

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1153): error C2086: 'int WINGDIAPI' : redefinition

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1152) : see declaration of 'WINGDIAPI'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1153): error C2146: syntax error : missing ';' before identifier 'glAlphaFunc'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1153): error C2182: 'APIENTRY' : illegal use of type 'void'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1153): error C2086: 'int APIENTRY' : redefinition

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1152) : see declaration of 'APIENTRY'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1154): error C2146: syntax error : missing ';' before identifier 'GLboolean'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1154): error C2501: 'WINGDIAPI' : missing storage-class or type specifiers

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1154): error C2086: 'int WINGDIAPI' : redefinition

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1152) : see declaration of 'WINGDIAPI'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1154): error C2146: syntax error : missing ';' before identifier 'glAreTexturesResident'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1154): error C2371: 'APIENTRY' : redefinition; different basic types

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1155): error C2144: syntax error : 'void' should be preceded by ';'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1155): error C2501: 'WINGDIAPI' : missing storage-class or type specifiers

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1155): error C2086: 'int WINGDIAPI' : redefinition

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1155): error C2146: syntax error : missing ';' before identifier 'glArrayElement'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1155): error C2182: 'APIENTRY' : illegal use of type 'void'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1155): error C2086: 'int APIENTRY' : redefinition

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1156): error C2144: syntax error : 'void' should be preceded by ';'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1156): error C2501: 'WINGDIAPI' : missing storage-class or type specifiers

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1156): error C2086: 'int WINGDIAPI' : redefinition

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1156): error C2146: syntax error : missing ';' before identifier 'glBegin'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1156): error C2182: 'APIENTRY' : illegal use of type 'void'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1156): error C2086: 'int APIENTRY' : redefinition

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1157): error C2144: syntax error : 'void' should be preceded by ';'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1157): error C2501: 'WINGDIAPI' : missing storage-class or type specifiers

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1157): error C2086: 'int WINGDIAPI' : redefinition

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1157): error C2146: syntax error : missing ';' before identifier 'glBindTexture'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1157): error C2182: 'APIENTRY' : illegal use of type 'void'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1157): error C2086: 'int APIENTRY' : redefinition

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1158): error C2144: syntax error : 'void' should be preceded by ';'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1158): error C2501: 'WINGDIAPI' : missing storage-class or type specifiers

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1158): error C2086: 'int WINGDIAPI' : redefinition

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1158): error C2146: syntax error : missing ';' before identifier 'glBitmap'

C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\gl\GL.h(1158): error C2182: 'APIENTRY' : illegal use of type 'void'

This goes on and on for two pages http://www.opengl.org/discussion_boards/ubb/frown.gif

Am i doing something wrong here?

Is this why i need to use a wrapper?

Sorry for the bloated post and any "more" help would be appreciated

jra101
02-21-2004, 05:18 PM
Make sure to include windows.h before gl.h

rwilliams
02-21-2004, 06:13 PM
OMG ~DUH!~
Thanks