Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Trying QT5 + glew + QOpenGLContext, need help with error on glewInit
Forum Updated to NodeBB v4.3 + New Features

[Solved] Trying QT5 + glew + QOpenGLContext, need help with error on glewInit

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    infinicat
    wrote on last edited by
    #1

    I'm trying to use glew with Qt 5 but my code is failing on the call to glewInit with error "Missing GL version".

    I built a debug version of glew and stepped into the glewInit call. It is failing when it is trying to get the OpenGL version context when calling glGetString. glGetString is returning 0.

    I know that glew is not necessary because QOpenGLFunctions exists but I would much rather use glew if I can. I'm creating a QWindow and QOpenGLContext for my window and OpenGl context. I have checked that the version of the created window and OpenGL context does match my requested version.

    Things I've tried:

    1. Defining QT_NO_OPENGL before including QOpenGLContext header but then got these compilation errors:
      ..\main.cpp(24) : error C2512: 'QOpenGLContext' : no appropriate default constructor available
      ..\main.cpp(25) : error C2027: use of undefined type 'QOpenGLContext'

    2. Created a QWindow-derived class so I could move the glewInit() call to be when the the window is exposed (in exposeEvent()). Received same "Missing GL version" error.

    Did a search online but didn't find an answer. It looks like it's been done before. Is it that glew and QOpenGLContext can't be used together? That I need to write my own code to create context?

    I pasted example code below. Any suggestions or help would be appreciated. Thanks.

    This is what I'm using:
    Qt 5.3.2 for Windows 64-bit (VS 2013, OpenGL).
    Qt Creator 3.2.1.
    GLEW 1.11.0, linking to 64-bit static version
    Visual Studio 2013 Express
    Windows 7 64-bit

    main.cpp
    @#define GLEW_STATIC 1
    #include <GL/glew.h>

    #include <QGuiApplication>
    #include <QDebug>
    #include <QOpenGLContext>
    #include <QWindow>

    int main(int argc, char *argv[])
    {
    QGuiApplication a(argc, argv);

    QSurfaceFormat requestedFormat;
    requestedFormat.setVersion( 3, 3 );

    QWindow * window = new QWindow;
    window->setFormat( requestedFormat );
    window->show();

    QOpenGLContext * context = new QOpenGLContext;
    context->setFormat( requestedFormat );
    context->create();

    GLenum err = glewInit();
    if( GLEW_OK != err ){
    qDebug() << "[Error] GLEW failed to initialize. " << (const char*)glewGetErrorString(err);
    }

    return a.exec();
    }@
    </code>

    pro file:
    @QT += core gui

    TARGET = TEST
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    HEADERS +=

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../global/OpenGL/lib/x64/ -lglew32s
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../global/OpenGL/lib/x64/ -lglew32sd
    else:unix: LIBS += -L$$PWD/../../../global/OpenGL/lib/x64/ -lglew32s

    INCLUDEPATH += $$PWD/../../../global/OpenGL/include@

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You're not making the created context current, so basically glewInit is called without active OpenGL context. Call context->makeCurrent(window) before glewInit and context->doneCurrent() afterwards.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        infinicat
        wrote on last edited by
        #3

        Thank you. That worked.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved