Resolving OpenGL functions using glew in QT

All problems solved now.

First problem was : QT 5.0.1 does not support opengl by default. You have to compile it with -opengl desktop. Here is tutorial on how to compile QT with vs2010. Or you can download new opengl build from QT.

Second problem in adding glew libraries to project. If you add glew32s.lib (static) then you have to add "#define GLEW_STATIC" before "#include " It is advised to use glew32.lib (dynamic).

Third problem was segment fault on some opengl functions even if your GPU supports version 4.3. GLEW obtains information on the supported extensions from the graphics driver. Experimental or pre-release drivers, however, might not report every available extension through the standard mechanism, in which case GLEW will report it unsupported. To circumvent this situation, the glewExperimental global switch can be turned on by setting it to GL_TRUE before calling glewInit(), which ensures that all extensions with valid entry points will be exposed.

Took 18 days to solve these problems, glad now can start actual programming.


Following code compiles just FINE on MSVC2008 express, qt 4.8.1 and glew version 1.7.0

main.cpp:

#include <GL/glew.h>
#include <QApplication>
#include <QGLWidget>

int main(int argc, char** argv){
    glewInit();//<<-- glew function
    QApplication app(argc, argv);
    QGLWidget widget;

    GLuint arr;
    glGenVertexArrays(1, &arr);//<--no linker error (added just for testing, most likely won't gen arrays)

    widget.show();
    return app.exec();
}

gltest.pro:

TEMPLATE = app
TARGET = 
DEPENDPATH += .
INCLUDEPATH += . d:/c++/libs/include
LIBS += -L"d:/c++/libs/lib" -lglew32

CONFIG += console
QT += opengl

# Input
SOURCES += main.cpp

I assume that with Qt 5 situation won't be any different.

Feel free to override QGLWidget's paintGL and draw whatever you want using extensions. I don't have a code snippet nearby for that.

Suggestions:
1. Use precompiled binaries.
2. It might make sense to use dynamically-linked version of glew.
3. Notice header inclusion order.

According to some people

People say many things, you don't need to believe all of them.

Tags:

Opengl

Qt

Glew