Board index » cppbuilder » OpenGL rendering to a TPaintBox?

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 );

Quote
}

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

 

Re:OpenGL rendering to a TPaintBox?


Download the TOpenGLPanel from my website. It uses a TPanel
rather than a TPaintBox but does what you want. Feel free to "rip
off" the source for another component. I got it from the OpenGL
SuperBible - more or less.

Arnold the Aardvark
http://www.foxholly.demon.co.uk

Other Threads