View Full Version : opengl with c++ .Net windows form
avihai
09-04-2003, 01:03 AM
I'm trying to show graphics using opengl on a control on a windows form in visual c++ .net.
the controls I use are a picture box or a panel control.
the problem is the hwnd and hdc i can get are of type IntPtr. therefore, the wglCreateContext function doesn't work.
anyone knows how to convert IntPtr to HDC or another function that can be used???
Deiussum
09-04-2003, 05:37 AM
I got the start of a Managed C++ class that acts as a wrapper to OpenGL, and I just use an explict cast on the ToPointer() method like so:
Edit: Realized I should probably add a bit more code
// In my GDI class
System::IntPtr Gdi::GetDC(System::IntPtr hWnd)
{
return ::GetDC((HWND)hWnd.ToPointer());
}
// In my WGL class
System::IntPtr Wgl::wglCreateContext(System::IntPtr hdc)
{
System::IntPtr hGlRc;
hGlRc = ::wglCreateContext((HDC)hdc.ToPointer());
if (hGlRc == NULL)
{
throw new System::Exception("Error in wglCreateContext");
}
return hGlRc;
}
// In my C# test app
hDC = Gdi.GetDC(this.Handle);
iPixelFormat = Gdi.ChoosePixelFormat(hDC, oPfd);
Gdi.DescribePixelFormat(hDC, iPixelFormat, 40, oPfd);
Gdi.SetPixelFormat(hDC, iPixelFormat, oPfd);
hGLRC = Wgl.wglCreateContext(hDC);
Wgl.wglMakeCurrent(hDC, hGLRC);
Gdi.ReleaseDC(this.Handle, hDC);
[This message has been edited by Deiussum (edited 09-04-2003).]
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.