Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using makeCurrent() wrong?
Forum Updated to NodeBB v4.3 + New Features

Using makeCurrent() wrong?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 232 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    peytuk
    wrote on last edited by
    #1

    This is my resizeGL() function, I can see my cubes with no problem when I resize the window.

    void OGLWidget::resizeGL(int w, int h)
        {
            static float aspectRatio;
            if(w < h) aspectRatio = (float)h / (float)w;
            else      aspectRatio = (float)w / (float)h;
            glViewport(0,0,w,h);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
        
            gluPerspective(30, aspectRatio , 1.0, 1000);
            const float radius = sqrt(200 * 200 * 2);
            static float angle;
            const float x = radius * cos(angle * M_PI / 180),
                        y = radius * sin(angle * M_PI / 180);
            gluLookAt(x, y, 200, 0, 0, 0,  0, 0, 20);
            angle += 1;
        }
    

    When I try to do this inside on_pushButton_clicked() it only clears the screen and nothing happens but screen is cleared,

    void MainWindow::on_pushButton_clicked()
    {
        ui->widget->makeCurrent();
        const float radius = sqrt(300 * 300 * 2);
        static float angle;
        const float x = radius * cos(angle * M_PI / 180),
                    y = radius * sin(angle * M_PI / 180);
        gluLookAt(x, y, 300, 0, 0, 0,  0, 0, 20);
    
        angle += 10;
        ui->widget->doneCurrent();
        ui->widget->update();
    }
    

    Thanks

    W 1 Reply Last reply
    0
    • P peytuk

      This is my resizeGL() function, I can see my cubes with no problem when I resize the window.

      void OGLWidget::resizeGL(int w, int h)
          {
              static float aspectRatio;
              if(w < h) aspectRatio = (float)h / (float)w;
              else      aspectRatio = (float)w / (float)h;
              glViewport(0,0,w,h);
              glMatrixMode(GL_PROJECTION);
              glLoadIdentity();
              glMatrixMode(GL_MODELVIEW);
              glLoadIdentity();
          
              gluPerspective(30, aspectRatio , 1.0, 1000);
              const float radius = sqrt(200 * 200 * 2);
              static float angle;
              const float x = radius * cos(angle * M_PI / 180),
                          y = radius * sin(angle * M_PI / 180);
              gluLookAt(x, y, 200, 0, 0, 0,  0, 0, 20);
              angle += 1;
          }
      

      When I try to do this inside on_pushButton_clicked() it only clears the screen and nothing happens but screen is cleared,

      void MainWindow::on_pushButton_clicked()
      {
          ui->widget->makeCurrent();
          const float radius = sqrt(300 * 300 * 2);
          static float angle;
          const float x = radius * cos(angle * M_PI / 180),
                      y = radius * sin(angle * M_PI / 180);
          gluLookAt(x, y, 300, 0, 0, 0,  0, 0, 20);
      
          angle += 10;
          ui->widget->doneCurrent();
          ui->widget->update();
      }
      

      Thanks

      W Offline
      W Offline
      wrosecrans
      wrote on last edited by
      #2

      @peytuk 99.99% of the time, you have no reason to do explicit makeCurrent calls. Use all of your OpenGL functions in the paintGL method.

      in the button click handler slot, just set some variables that you'll later use when you set up your view in paintGL, and tell it to update(). Don't do it right there in the slot.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @peytuk gluLookAt modifies existing modelview matrix, not replaces it. You need to reset it first before using gluLookAt.

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(x, y, 300, 0, 0, 0,  0, 0, 20);
        
        1 Reply Last reply
        1

        • Login

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