Resizing QGL Widget



  • I don't know how to properly resize my openGL viewport when the widgetsize is changed. it somehow works when i initially call myWidget->resize() - but once the widget is shown on screen, resize doesn't work anymore.

    here is my code:

    @int main (int argc, char **argv) {
    QApplication app(argc, argv);
    QGLFormat glFormat;
    glFormat.setVersion(4,2);
    glFormat.setProfile( QGLFormat::CompatibilityProfile);

    QGLWidget* render_qglwidget = new MyWidget(glFormat);

    glContext = (QGLContext *) render_qglwidget->context();
    glContext->makeCurrent();
    render_qglwidget->show();
    render_qglwidget->resize(720, 486);
    return app.exec();
    }@

    And in MyWidget (that inherits from QGLWidget) i have:

    @void MyWidget::resizeGL(int w, int h){
    glViewport(0,0,w,h);
    }

    void MyWidget::paintGL(){
    glBegin(GL_TRIANGLES);
    glVertex3f(1,0,0);
    glVertex3f(0,1,0);
    glVertex3f(0,0,1);
    glEnd();
    }@

    so - what i would expect is to see a white triangle, with one corner in the middle of the window, one in the top-middle of the window and one in the right-middle of the window. when the window opens, this is exactly the case (so the glViewport function seems to work) but when i start resizing the window, the triangle stays exactly the same size (i ould expect it to scale together with the window) although glViewport is called with new values and also paintGL is called

    What am I missing?



  • This happen wen toy can't see the glWidget expanding, try to glClearColor, to
    fill the background:

    @
    void MyWidget::resizeGL(int width, int height)
    {
    glViewport(0, 0, (GLint)width, (GLint)height);
    }

    void MyWidget::initializeGL()
    {
    glClearColor(0.0, 0.0, 0.0, 0.0);
    }

    void MyWidget::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }
    @



  • You need also to change projection matrix.


Log in to reply
 

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