I'd like to be able to render with OpenGL to a RECT as part of a plugin. But it needs to be offscreen so it doesn't affect the main application. But I'm running into an issue where I can't create a rendering context, maybe you can find my error.
Here is the original sample code:
uint16 nsPluginInstance::HandleEvent(void* aEvent)
{
NPEvent * event = (NPEvent *)aEvent;
switch (event->event) {
case WM_PAINT:
{
if(!mWindow)
break;
// get the dirty rectangle to update or repaint the whole window
RECT * drc = (RECT *)event->lParam;
if(drc)
FillRect((HDC)event->wParam, drc, (HBRUSH)(COLOR_ACTIVECAPTION+1));
else {
RECT rc;
rc.bottom = mWindow->y + mWindow->height;
rc.left = mWindow->x;
rc.right = mWindow->x + mWindow->width;
rc.top = mWindow->y;
FillRect((HDC)event->wParam, &rc, (HBRUSH)(COLOR_ACTIVECAPTION+1));
}
break;
}
case WM_KEYDOWN:
{
Beep(1000,100);
break;
}
default:
return 0;
}
return 1;
}
And here, I'm trying to create a rendering context without creating a window. But the message box comes up with "Can't Create A GL Rendering Context."...
uint16 nsPluginInstance::HandleEvent(void* aEvent)
{
NPEvent * event = (NPEvent *)aEvent;
switch (event->event) {
case WM_PAINT:
{
if(!mWindow)
break;
// get the dirty rectangle to update or repaint the whole window
RECT * drc = (RECT *)event->lParam;
if(drc)
FillRect((HDC)event->wParam, drc, (HBRUSH)(COLOR_ACTIVECAPTION+1));
else {
RECT rc;
rc.bottom = mWindow->y + mWindow->height;
rc.left = mWindow->x;
rc.right = mWindow->x + mWindow->width;
rc.top = mWindow->y;
//FillRect((HDC)event->wParam, &rc, (HBRUSH)(COLOR_ACTIVECAPTION+1));
HWND hWND=(HWND)mWindow->window;
if (!hWND)
MessageBox(NULL,"Can't get the window handle.","ERROR",MB_OK|MB_ICONEXCLAMATION);
else
{
char message[50] = {0};
wsprintf(message, "Found Window Handle: %hu", hWND);
MessageBox(NULL,message,"ERROR",MB_OK|MB_ICONEXCLAMATION);
}
HDC hDC = GetDC(hWND);
if (!hDC)
MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
else
{
char message[50] = {0};
wsprintf(message, "Found GL Device Context: %hu", hDC);
MessageBox(NULL,message,"ERROR",MB_OK|MB_ICONEXCLAMATION);
}
HGLRC hRC = wglCreateContext(hDC);
if(!hRC)
MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
if(!wglMakeCurrent(hDC,hRC))
MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
}
break;
}
case WM_KEYDOWN:
{
Beep(1000,100);
break;
}
default:
return 0;
}
return 1;
}
[Edited by - tgraupmann on March 19, 2005 7:35:10 PM]