Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Resizing QGL Widget
QtWS25 Last Chance

Resizing QGL Widget

Scheduled Pinned Locked Moved Game Development
3 Posts 3 Posters 4.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    supergnu
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      msx_br
      wrote on last edited by
      #2

      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);
      }
      @

      msx_br - Brazil (Netherlands)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        minimoog77
        wrote on last edited by
        #3

        You need also to change projection matrix.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved