2

I'm trying to write the code for the picking in my desktop app in C++ in Qt creator. I'm totally new in Qt and C++ (apologise for my ignorance), I have read a lot of example and all of them are using Glut, Glu and\or glew.

I follow this code : https://github.com/tatsy/QtOpenGLMousePick

and i tryed to include the lib, but i'm not sure about all the step that it's necessary do. Can someone explain them please?

After tried a lot of way to include the lib of glut and glew my code still give the errors:

C: ... \glwidget.cpp:266: error: undefined reference to `gluPickMatrix@36'
C: ... \glwidget.cpp:268: error: undefined reference to `gluPerspective@32'

I'm using : Qt Creator 4.4.1 Based on Qt 5.9.2 (MSVC 2015, 32 bit)

My code is :

void GLWidget::mousePressEvent(QMouseEvent* ev) {
    // Selection buffer
    std::fill(selectBuffer.begin(), selectBuffer.end(), 0);
    //-(selectBufferSize, &selectBuffer[0]);

    // Draw for selection buffer
    glRenderMode(GL_SELECT);

    // Matrix setting
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    int viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);
    gluPickMatrix(50, 50, 5, 5, viewport);
    const float aspect = static_cast<float>(viewport[2]) / viewport[3];
    gluPerspective(45.0, aspect, 1.0, 1000.0);

    // Draw
    paintGL();

    // Reset matrix setting
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    // Revert render mode
    int hits = glRenderMode(GL_RENDER);

    // Show selection
    printf("%d hits\n", hits);
    if (hits > 0) {
        int id = 0;
        for (int i = 0; i < hits; i++) {
            printf("Level: %u\n", selectBuffer[id + 0]);
            printf("  Min: %f\n", (double)selectBuffer[id + 1] / UINT_MAX);
            printf("  Max: %f\n", (double)selectBuffer[id + 2] / UINT_MAX);
            printf("   ID: %u\n", selectBuffer[id + 3]);
            id += 4;
        }
    }
}

Of course I'm including :

#include <gl/GLU.h>
#include <gl/glut.h>

and in my .pro :

LIBS += -lOpengl32
LIBS += -LD:\Qt\5.9.2\mingw53_32\lib\libQt5OpenGL.a -lopengl32
LIBS += -lglut
LIBS += -LC:\MinGW\lib\libglut.a -lglut

win32:CONFIG(release, debug|release): 
LIBS += -L$$PWD/../../../../../Downloads/glutcu/lib/ -lglut32cu
else:win32:CONFIG(debug, debug|release): 
LIBS += -L$$PWD/../../../../../Downloads/glutcu/lib/ -lglut32cu
else:unix: LIBS += -L$$PWD/../../../../../Downloads/glutcu/lib/ -lglut32cu

INCLUDEPATH += $$PWD/../../../../../Downloads/glutcu/include
DEPENDPATH += $$PWD/../../../../../Downloads/glutcu/include

DISTFILES += \
    freeglut.dll \
    glew32.dll

0 Answers0