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???
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).]