How to replace following (deprecated) OpenGL funct

2019-07-04 21:43发布

问题:

I've got a simple application showing a custom frame buffer (it is sort of an emulator of the frame buffer functionality) using OpenGL:

void GLWidget::resizeGL( int w, int h )
{
    glViewport( 0, 0, w, h );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, w, 0, h, -1, 1 );
}

void GLWidget::paintGL()
{
    if( pScreen != 0 )
    {
        glRasterPos2i( 0, 2 * pScreen->height );
        glPixelZoom( 2, -2 );
        glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
        glDrawPixels( pScreen->width, pScreen->height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pScreen->pixels );
    }
}

Really, this is all I want to do it, no shaders, no fancy tricks, just the double zoom and show. This code is years old and while porting it to Windows I've noticed that it wont compile anymore. First I thought it's a Windows specific thing but then I realized it's actually the new OpenGL Windows 7 comes with (unlike Arch Linux I'm using on daily basis).

So what to do about that? I really don't feel like installing a custom math library for the matrix stuff, I can't believe the latest OpenGL can't "just show the buffer".

回答1:

I'll have to answer this for myself. After a long research, I finally found the case. This answer gives perfect explanation what's going on. Also, I somehow missed this in the Qt download section:

The Windows offline installers are by default ANGLE based.

what leads to even more sophisticated explanation, in short:

Qt 5 on Windows can be configured to use either OpenGL drivers, or DirectX drivers through the ANGLE library.

I'm surprised that so few (one?) SO answers mention this. A lot of scary stuff about contexts, quads, shaders but the solution is really simple. Hopefully it will help someone.