Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

OpenGL gluPickMatrix not existing



  • I tryed out a example for opengl which was for QT4. However now i use QT 5.12.4 and i get error with this command:

        gluPickMatrix(GLdouble(pos.x()), GLdouble(viewport[3] - pos.y()),
                      5.0, 5.0, viewport);
    

    According from the web the Header QtOpenGL does not include anymore "OpenGL/glu.h" which is required for this command.

    I tryed to include OpenGL/glu.h but it looks like it does not exist?

    How can i add it. Im using KDE Neon (Linux).


  • Lifetime Qt Champion

    Hi,

    IIRC this header comes from the glu library. On Debian it's the libglu1-mesa-dev package.



  • OK i could install it. But what else do i have to do that the project finds it?


  • Lifetime Qt Champion

    Taking a look at the package content, the header is under "GL/glu.h".



  • I added the header however its not found.

    Steps i took:

    sudo apt-get update
    sudo apt-get install libglu1-mesa-dev
    

    Restart the project and

    #include "gl/glu.h"


  • Lifetime Qt Champion

    Casing is important.



  • Ok I changed it to the correct:

    "GL/glu.h".

    It looks like it is found. However when i compile i still get an error with the gluPickMatrix like this:

    ../tetrahedron/tetrahedron.cpp:128: undefined reference togluPickMatrix'
    `


  • Lifetime Qt Champion

    You need to also link to libGLU.



  • GLU was last updated in the 1990's, it's basically deprecated, and depends on functionality that was deprecated from OpenGL years ago. Ideally you should find a different way of doing what you are trying to accomplish. If you are using any kind of modern OpenGL with vertex shaders from the last ~15 - 20 years, GLU will have no idea how to understand your projection matrices, and the results it gives you will be nonsensical or wrong even if you get it working.



  • The whole code which uses the gluPickMatrix looks like this.

    int Tetrahedron::faceAtPosition(const QPoint &pos)
    {
        constexpr int MaxSize = 512;
        GLuint buffer[MaxSize];
        GLint viewport[4];
    
        makeCurrent();
    
        glGetIntegerv(GL_VIEWPORT, viewport);
        glSelectBuffer(MaxSize, buffer);
        glRenderMode(GL_SELECT);
    
        glInitNames();
        glPushName(0);
    
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
        gluPickMatrix(GLdouble(pos.x()), GLdouble(viewport[3] - pos.y()),
                      5.0, 5.0, viewport);
        GLdouble x = GLdouble(width()) / height();
        glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
        draw();
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
    
        if (!glRenderMode(GL_RENDER)) {
            return -1;
        }
        return static_cast<int>(buffer[3]);
    }
    

    What would be an alternative?

    And how can i link against libGLU?


  • Qt Champions 2019

    @sandro4912 said in OpenGL gluPickMatrix not existing:

    And how can i link against libGLU?
    Add

    LIBS += -lGLU
    

    to your pro file.



  • The linking worked.

    However i found this approach to implement gluPickMatrix and not need the glu library:

    void gluPickMatrix(
            GLdouble x, GLdouble y, GLdouble deltax, GLdouble deltay,
            GLint viewport[4])
    {
       if (deltax <= 0 || deltay <= 0) {
           return;
         }
    
       /* Translate and scale the picked region to the entire window */
       glTranslated((viewport[2] - 2 * (x - viewport[0])) / deltax,
               (viewport[3] - 2 * (y - viewport[1])) / deltay, 0);
       glScaled(viewport[2] / deltax, viewport[3] / deltay, 1.0);
    }
    

Log in to reply