Using QPainter over OpenGL in QGLWidget when using shaders

前端 未结 2 1780
难免孤独
难免孤独 2021-01-02 06:31

Many of you Qt (4.6 specifically) users will be familiar with the Overpainting example supplied in the OpenGL tutorials, I\'m trying to do something very similar but using s

2条回答
  •  星月不相逢
    2021-01-02 07:08

    Call beginNativePainting() before making OpenGL calls. A glPush/Pop of the OpenGL state may also be necessary. Try something like the following:

    QPainter p( this );
    p.beginNativePainting();
    
    // Maybe necessary
    glPushAttrib(GL_ALL_ATTRIB_BITS);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    
    // Put OpenGL code here
    
    // Necessary if used glPush-es above
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glPopAttrib();
    
    p.endNativePainting();
    
    p.fillRect( 10, 10, 100, 100,
            QColor( 255, 0, 0 ) );
    

提交回复
热议问题