Qt gets matrix data



  • I am drawing some 3D graphics on QOpenGLWidget. I want to use glGetFloatv(GL_MODELVIEW_MATRIX, m) to get the model-view matrix. But a problem occurs. When I use this function in my paintGL loop. I can get the right results. When I put this function in the mousePressEvent, the matrix m always an unit matrix.
    Is it related to the Thread? Thanks in advance.
    Qt Creator 5.9.1 on windows10

    float m[16];
    
    void Coordinary::paintGL()
    {
        const qreal retinaScale = devicePixelRatio();
        glViewport(0, 0, width() * retinaScale, height() * retinaScale);
    
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    
        glBegin(GL_TRIANGLES);
    
        glColor3f(1.0f,0.2f,0.3f);
        glVertex3f(1.0f,0.0f,0.0f);
        glColor3f(0.4f,1.0f,0.8f);
        glVertex3f(0.0f,1.0f,0.0f);
        glColor3f(0.1f,0.7f,1.0f);
        glVertex3f(0.0f,0.0f,1.0f);
    
        glEnd();
    
        update();
    
        glGetFloatv(GL_MODELVIEW_MATRIX, m);
    }
    
    void Coordinary::mousePressEvent(QMouseEvent *event)
    {
        if(event->button() == Qt::RightButton)
        {
            glGetFloatv(GL_MODELVIEW_MATRIX, m);
        }
    }
    
    


  • Hi @Qt_crazyer

    i'm really not into OpenGL but try the QOpenGLFunctions:

    QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions();
    glFuncs-> glGetFloatv(GL_MODELVIEW_MATRIX, m);
    

Log in to reply
 

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