|
From: Lloyd D. <ll...@ga...> - 2001-10-20 12:44:44
|
Hello fellow C# users....
i am trying to improve my C# OpenGL library by enabling to create OpenGL
context on any HDC... (printer, image, form, ....)
for this i create a new OpenGLContext class which have
a constructor like this:
-------------------------------------
[DllImport("csogl")]
IntPtr GLContextInitFromHDC(InpPtr p);
public OpenGLContext(Graphics g)
{
ctxt = GLContextInitFromHDC(g.GetDc());
}
---------------------------------
i use it like this
Bitmap b = new Bitmap(400, 400);
Graphics g = Graphics.FromImage(b);
OpenGLContext ogc = new OpenGLContext(g);
but when i try to call (win32) SetPixelFormat function this fail with
error 126 (ERROR_MOD_NOT_FOUND) , what this could be ?
here is my true interop code...
-- Warning: C - code --------------
typedef struct HG3D
{
HWND wnd;
HDC gdi;
HGLRC glctxt;
}
G3D, * HG3D;
int GLContextInitFromHDC(HG3D ctxt, PIXELFORMATDESCRIPTOR * pix)
{
int format = ChoosePixelFormat(ctxt->gdi, pix);
if(!format) {
SetLastError(ERROR_INVALID_INDEX);
return 0;
}
if(ctxt->glctxt) {
SetLastError(ERROR_ALREADY_INITIALIZED);
return 0;
}
// -> // it failed HERE, with error 126: ERROR_MOD_NOT_FOUND
if(!SetPixelFormat(ctxt->gdi, format, pix))
return 0;
if(!ctxt->glctxt)
ctxt->glctxt = wglCreateContext(ctxt->gdi);
return (int) ctxt->glctxt;
-----------------------------------
|