点击qt按钮更新GL

时间:2016-04-13 17:41:20

标签: c++ qt opengl

我试图通过点击按钮更新qt中的GL。 这就是我在Widget类中的函数的样子:

void MyGLWidget::renderFromButton()
{
    model.drawAxis();
    paintGL();
}

void MyGLWidget::draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    GLfloat position[] = { 2.0, 2.0, 2.0, 1.0 };
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();


    gluLookAt
        (
        .05, .1, 2,
        0., 0., 0,
        0, 1, 0
        );

    static float rotation_transform[4][4];
    trackball.rotationMatrix( rotation_transform );
    glLightfv (GL_LIGHT0, GL_POSITION, position);
    glEnable (GL_LIGHTING);

    glPushMatrix();
    glScalef(scale, scale, scale);
    glTranslatef(transx, transy, transz);
    glRotatef(angle, 1, 0, 0);
    glMultMatrixf( &rotation_transform[0][0] ) ;

    glPopMatrix();
    glDisable (GL_LIGHTING);
    swapBuffers();
}

我在mianwindow的功能:

void MainWindow::on_pushButton_clicked()
{
    cout << "This Function Called" << endl;
    ui->myGLWidget->renderFromButton();
}

模型类的drawAxis()函数:

void Model::drawAxis(){
    glBegin(GL_LINES);
    double axis = 2;
    //drawing x -axis
    glColor4f(0, 0, 1, 0);
    glVertex3f( axis, 0, 0);
    glVertex3f(-axis, 0, 0);

    //drawing y -axis
    glColor4f(0, 1, 0, 0);
    glVertex3f(0, axis, 0);
    glVertex3f(0, -axis,0);

    //drawing z -axis
    glColor4f(1, 0, 0, 0);
    glVertex3f(0, 0, axis);
    glVertex3f(0, 0, -axis);
    glEnd();
}

当我直接在MyGLWidget :: draw()中调用model.drawAxis()时,它工作正常,但不能在给定的表单中工作。我尝试过updateGL(),paintGL()和update()。他们还有其他办法吗?

0 个答案:

没有答案