Qt5 and OpenGL with a Mac Retina display

  • With Qt 4.8.6 on Mac Yosemite, I was using a QOpenGL widget, setting the glViewport() using the values passed in by resizeGL(). And then using:

    gluOrtho2D(m_World.left(), m_World.right(), m_World.bottom(), m_World.top());

    where m_World was my actual drawing coordinates. This all worked fine. The only bug was that Qt 4 did not handle icon sizes correctly on the retina display - they were twice as big as they should have been. This was fixed in Qt 5.x with the devicePixelRatio() command that allowed you to get the device pixel coordinate ratio.

    However, I', still not clear how to use it and where. Do I apply it to the viewport I use for mapping between world and viewport coords using:

    glGetIntegerv(GL_VIEWPORT, m_Viewport);
    and multiplying the m_Viewport coords by the devicePixelRatio() ? Reason is I am finding my data that has the bounding box of m_World is shifted and goes outside the viewport - it appears to be double the size it should be.

  • OK so the solution is to scale the viewport by devicePixelRatio(). And, if you're using textures, scale them too. and just about anything else that openGL is doing, as it is assuming your viewport coords are pixels, which they are not...

Log in to reply

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