Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

QPainter on a QGLWidget using VBOs



  • I have a QGLWidget that I wish to overpaint onto with a QPainter. I have followed the various examples out there to do this, but I still cannot seem to get it to work properly when I am using VBOs. I have the source code available "here":https://dl.dropboxusercontent.com/u/36712950/QtGlText.tgz

    The most relevant sections of code are as follows:

    @
    void
    GlWidget::
    paintEvent( QPaintEvent* event )
    {
    if ( !updatesEnabled() )
    {
    // do not update this widget
    return;
    }

    if ( !isValid() )
    {
    // no valid render context
    return;
    }

    // make sure this render context is the active one
    makeCurrent();

    QPainter painter;
    painter.begin( this );
    painter.setRenderHint( QPainter::Antialiasing );

    #ifndef NO_2D_3D_MIX
    // begin OpenGL calls
    painter.beginNativePainting();
    #endif

    // Save the current OpenGL state (extra paranoid)
    glPushAttrib( GL_ALL_ATTRIB_BITS );
    glMatrixMode( GL_PROJECTION );
    glPushMatrix();
    glMatrixMode( GL_MODELVIEW );
    glPushMatrix();

    // setup the viewport
    resizeGL( width(), height() );

    // pre-render callback
    preRender();

    // begin rendering
    emit rendering();

    // 3D render
    paintGL();

    // Restore OpenGL state
    glMatrixMode( GL_MODELVIEW );
    glPopMatrix();
    glMatrixMode( GL_PROJECTION );
    glPopMatrix();
    glPopAttrib();

    // make sure there are no loaded shader programs
    glUseProgram( 0 );
    glBindBuffer( GL_ARRAY_BUFFER, 0 );

    #ifndef NO_2D_3D_MIX
    // end OpenGL calls
    painter.endNativePainting();

    // 2D render
    render2d( &painter );
    #endif

    // post-render callback
    postRender();

    // end painting and swap the buffers
    painter.end();
    }
    @

    and

    @
    void
    TestWidget::
    render3d()
    {
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // This works
    glBegin( GL_TRIANGLES );
    glColor3ub( 255, 15, 125 );
    glVertex3f( -0.85, -0.90, 0.8 ); // triangle #1
    glVertex3f( 0.90, -0.90, 0.8 );
    glVertex3f( 0.90, 0.85, 0.8 );

    glVertex3f( -0.90, -0.85, 0.8 ); // triangle #2
    glVertex3f( 0.85, 0.90, 0.8 );
    glVertex3f( -0.90, 0.90, 0.8 );
    glEnd();

    // Bind the shader program
    m_shader.bind();

    // Bind the vertex buffers
    m_vertexBuffer.bind();

    // draw them
    glDrawArrays( GL_TRIANGLES, 0, NUM_VERTS );
    }
    @

    A couple of things to note are that the fixed-function OpenGL calls (glBegin, glVertex, glEnd) work properly and draw. The vertex buffer items only draw when I define 'NO_2D_3D_MIX'. I feel like I must be missing something simple here, but I cannot figure out what.

    Due to other constraints I am using Qt v4.8.5, Mesa-9.2.1 GL headers with the nVidia 304.43 run-time drivers on a 64-bit RedHat Linux machine.

    Thanks in advance for any possible help.


Log in to reply