OpenGL rendering to a TPaintBox?
Has anyone gotten this to work?
I have OpenGL working fine to a form. But, I'd like it to render into a
PaintBox component which is placed on top of my main form. Here's my
code and where it blows up:
void __fastcall TForm1::ButtonCreateGLClick(TObject *Sender)
{
int i;
PIXELFORMATDESCRIPTOR pfd;
RECT rect;
// grab device context
hdc = PaintBoxRender->Canvas->Handle;
// figure out pixel format
memset( &pfd, 0, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
if ( !( i = ChoosePixelFormat( hdc, &pfd ) ) )
{
DisplayLastError();
return;
}
// set pixel format
if ( !SetPixelFormat( hdc, i, &pfd ) )
{
DisplayLastError();
return;
}
// create gl context
if ( !( hglrc = wglCreateContext( hdc ) ) )
{
DisplayLastError();
return;
}
// make it the current context
if ( !wglMakeCurrent( hdc, hglrc ) ) /* <---- THIS FAILS!!! ----> */
{
DisplayLastError();
return;
}
// set up viewport
glViewport( 0, 0, PaintBoxRender->Width, PaintBoxRender->Height );
My call to wglMakeCurrent() is failing with the error: "The requested
transformation operation is not supported." (which really confuses me!).
Any ideas appreciated!!!
Thanks for helping,
Steve