سؤال

I have a QMainWindow containing two QGLWidgets. The widgets use the default constructor and do not share a context. The widgets both display two dimensional data and allow for clicking and dragging.

This works using gluUnproject and works well on the first QGLWidget that is created. When clicking on the second widget, everything works as expected. However, when dragging the second widget, the movement is not smooth. What's worse is that once the second widget has been dragged, the first widget's gluUnproject is off by some margin that appears related to the direction and distance the second display was dragged.

I have tried calls to makeCurrent() at the start of the drawing method, at the start of the mouse event, and combinations of one, the other, and both and haven't seen any improvement.

void MyGLWidget::paintEvent(QPaintEvent *event){
    glViewport(0, 0, widgetWidth, widgetHeight);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90,(GLfloat)((widgetWidth/widgetHeight)),0.1f,-zoomMin);
    glTranslatef(camera.x, camera.y, camera.zoom);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //[GL Drawing code]

    glGetDoublev( GL_MODELVIEW_MATRIX, _modelview );
    glGetDoublev( GL_PROJECTION_MATRIX, _projection );
    glGetIntegerv( GL_VIEWPORT, _viewport );
}
هل كانت مفيدة؟

المحلول

Make sure that the viewport and matrix data you pass to gluUnProject match those of the widget you're interacting with. Ideally you create copies of them at drawing time into some widget class member variable.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top