Qt5.4 and GLEW MX => glewInit() fails
-
Hi,
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 <GL/glew.h>
#include <qopenglwidget.h>
#include <qopenglcontext.h>
#include <qwindow.h>
#include <qapplication.h>//Function used by GLEW to support multiple rendering contexts.
#define glewGetContext() ctx::_glewGetContext()class ctx {
public:
static GLEWContextStruct* _glewGetContext()
{
if (s_glewCtx == NULL)
s_glewCtx = new GLEWContextStruct;
return s_glewCtx;
}private:
static GLEWContextStruct* s_glewCtx;
};GLEWContext* ctx::s_glewCtx = NULL;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
bool errQt;
int errGlew;
GLenum errorGL;QSurfaceFormat requestedFormat;
requestedFormat.setVersion(3, 3);//Create context
QOpenGLContext context;
context.setFormat(requestedFormat);
errQt = context.create(); //true//Creates the QGLWidget using the current context:
QOpenGLWidget widget;
widget.winId();
widget.setFormat(requestedFormat);//Bind context
errQt = context.makeCurrent(widget.windowHandle()); //true//Init glew
errorGL = glGetError(); //0
errGlew = glewInit(); //0
errorGL = glGetError(); //1280//Release context
context.doneCurrent();
}@When I remove the setFormat() for both the context and widget, it passes. But I need OpenGL 3.3.
Any suggestion ? Is GLEW alright with Qt5.4 ?