QOpenglWindow PaintGL() Native gl calls cause painter to disappear SOLVED



  • I've subclassed a QOpenglWindow, connected its update slot to its frameSwapped signal, and it merrily animates along.

    I'm able to use Qpainter on the window to render some nice animated text, with glClear wiping the buffer each frame.

    However, when I add some more fancy gl calls, the painter stuff gets wiped out. Remove the other gl calls, it's back. I've tried painting before and after the gl calls, wrapping them in beginNativePanting() and endNativePainting(), to no avail. Does anybody have any ideas?

    Thanks

    Here's my paintGL function, minus some non-drawing animation stuff:
    @
    void PlaybackWindow::paintGL()
    {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
                    
                                                                               
                                                                               
    //painter.beginNativePainting();                                           
    
    
    m_program->bind();
    
    QMatrix4x4 matrix;
    matrix.setToIdentity();
    matrix.perspective(60, 4.0/3.0, 0.1, 100.0);
    matrix.lookAt(QVector3D(0.0,8.0,-20.0),QVector3D(0,0,0),QVector3D(0,1,0));
    m_program->setUniformValue(m_matrixUniform, matrix);
    

    if(validbuffer && pb1size > 0)
    {
    glBindBuffer(GL_ARRAY_BUFFER,vertex_buffer_1);
    glEnableVertexAttribArray(m_posAttr);
    glVertexAttribPointer(m_posAttr,3 , GL_FLOAT, GL_FALSE, 0, 0);

        glPointSize(4);
        glDrawArrays(GL_POINTS, 0, pb1size);
    }
    
    
    glDisableVertexAttribArray(m_posAttr);
    
    m_program->release();
    

    //painter.endNativePainting();

    QPainter painter;
    painter.begin(this);
    painter.setPen(Qt::white);
    painter.setFont(QFont("Arial", 30));
    painter.drawText(10,120, QString::number(m_Engine->GetFrameNum()) );
    painter.end();
    }
    @



  • FIxed it by declaring

    glBindBuffer(GL_ARRAY_BUFFER,0);

    after releasing the program.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.