Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-41105

OpenGL renderText has problems on Mac Retina displays

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 5.5.0 Beta
    • 5.3.1
    • GUI: OpenGL
    • None
    • Mac OS 10.9.4.
    • macOS
    • 5c379f3ff0471c51827577d047c93bab88ad44ce

      This appears to be related to QTBUG-31000, however that issue is marked as resolved, so I'm assuming it's different in some way.

      When I use renderText to draw text on my OpenGL display I have problems when the application is on my Laptop screen (retina). When I'm on my external display (non-retina) it looks fine. What I see is that the text is not over the place that it should be when I'm on my laptop display.

      I have also noticed that when I try and get the location that the user clicks using glReadPixels and converting I get the wrong location on my laptop display and the right location on my external display. I've managed to fix that code by taking device pixel ratio into account.

      void getGLCoordinates(int const mouseX,
              int const mouseY,
              double &glX,
              double &glY,
              double &glZ) {
          makeCurrent();
          glPushMatrix();
          performAllTranslations(); // make sure that the rotation matrix is correct
      
          glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
          glGetDoublev(GL_PROJECTION_MATRIX, projection);
          glGetIntegerv(GL_VIEWPORT, viewport);
      
          // handle high resolution displays
          double const devicePixelRatio =
                  windowHandle() ? windowHandle()->devicePixelRatio() : 1;
          viewport[2] = viewport[2] / devicePixelRatio;
          viewport[3] = viewport[3] / devicePixelRatio;
      
          GLdouble const winX = mouseX;
          GLdouble const winY = viewport[3] - mouseY;
          GLfloat winZ = 0;
          glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
          winZ = winZ / devicePixelRatio;
      
          gluUnProject(winX, winY, winZ, modelview, projection, viewport, &glX, &glY,
                  &glZ);
      
          LOG4CXX_TRACE(LOGGER, "--------")
          LOG4CXX_TRACE(LOGGER,
                  " viewport: " << viewport[0] << " " << viewport[1] << " " << viewport[2] << " " << viewport[3])
          LOG4CXX_TRACE(LOGGER, " mouse: " << mouseX << ", " << mouseY)
          LOG4CXX_TRACE(LOGGER, " window: " << winX << ", " << winY << ", " << winZ)
          LOG4CXX_TRACE(LOGGER, " opengl: " << glX << ", " << glY << ", " << glZ)
          LOG4CXX_TRACE(LOGGER, "zoom: " << zoomFactor //
                  );
          LOG4CXX_TRACE(LOGGER,
                  "pixel ration: " << (windowHandle() ? windowHandle()->devicePixelRatio() : -1));
          LOG4CXX_TRACE(LOGGER, "--------")
      
          glPopMatrix();
      }
      

      However I haven't been able to fix renderText yet. I'm using the version of renderText that takes 3 doubles as parameters.

      All of this worked fine in Qt4 on the same system, it's only broken in Qt5.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            sorvig Morten Sørvig
            jschewe Jon Schewe
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes