0

We are migrating our project from Qt 4.8 to 5.4. We use multiple contexts in multiple thread. We use GLEW MX for this purpose (We make the context we desire current then call glewInit() on a local instance of GLEWContextStruct).

I'm trying to change QGLWidget and QGLContext to QOpenGLWidget and QOpenGLContext but I ended up not being able to initialize glew anymore. GLEW doesn't return an error but glGetError() does.

I did install Qt 5.4 64 with OpenGL version.

Here is the code reduced to a minimum :

#include <QtWidgets/QApplication>

#define GLEW_MX
#define GLEW_STATIC
#include <GL/glew.h>

#include <qopenglcontext.h>
#include <qwindow.h>

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

    bool errQt;
    int errGlew;
    GLenum errorGL;

    QSurfaceFormat requestedFormat;
    requestedFormat.setVersion(3, 3);
    requestedFormat.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);

    //Creates the QGLWidget using the current context:
    QWindow window;
    window.setSurfaceType(QSurface::OpenGLSurface);
    window.setFormat(requestedFormat);
    window.create();

    //Create context
    QOpenGLContext context;
    context.setFormat(requestedFormat);
    errQt = context.create(); //true

    //Bind context
    context.makeCurrent(&window);

    //Glew context creation
    GLEWContext* pCtx = new GLEWContext; //All forwards undefined

    //Release context
    context.doneCurrent();

    return 1;
}

Any suggestion ? Is GLEW alright with Qt5.4 ?

EDIT 1 :

It appears the problem is not Qt related. The GLEWContext created doesn't have any function forward defined (all function pointers are undefined). The code has been updated to help the reviewer not lose focus.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
agrum
  • 407
  • 2
  • 16
  • Which OS? GPU? Drivers? Qt compiled with what OpenGL option? Where's your glewInit call? (As separate news, Qt now provides what GLEW provides via the QOpenGLContext::versionFunctions, QOpenGLExtensions, and the various QOpenGL* wrappers) – peppe Jan 24 '15 at 17:31

2 Answers2

0

I use glewInit() with Qt 5.4 in my project, but I'm using QWindow as my base class, not QOpenGLWidget.

In my ctor I do this:

QRiftWindow::QRiftWindow() {
 setSurfaceType(QSurface::OpenGLSurface);
 QSurfaceFormat format;
 format.setDepthBufferSize(16);
 format.setStencilBufferSize(8);
 format.setVersion(4, 3);
 format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
 setFormat(format);

 m_context = new QOpenGLContext;
 m_context->setFormat(format);
 m_context->create();
 ...

I execute my OpenGL work on a separate thread. Once the thread has started I call an setup method on my class

m_context->makeCurrent(this);
glewExperimental = true;
glewInit();
glGetError();

I've previously done this exact same setup with OpenGL 3.3 and had no issues.

Jherico
  • 28,584
  • 8
  • 61
  • 87
  • I updated my code following your answer and ended up with the same issue. Let me know if I did something wrong or if you have any additional suggestion. Thanks. – agrum Jan 24 '15 at 01:04
0

You should actually get a warning about that:

#warning qopenglfunctions.h is not compatible with GLEW, GLEW defines will be undefined

#warning To use GLEW with Qt, do not include or after glew.h

Your "qopenglcontext.h" includes . To answer your question, you can use Qt + GLEW, but u can't easily mix up Qt-opengl with GLEW.

user3054986
  • 417
  • 7
  • 18