GLEW and Qt 5, "Missing GL version"
-
I have searched Google and the Qt site for solutions. I am using #define QT_NO_OPENGL_ES_2 to allow the glew headers to work okay. I am creating a custom QGLWidget (following tutorials), and calling glewInit() from within the initializeGL() method. One or two posts seemed to indicate that this is the correct method for how to ensure that you have a valid GL context.
I have also tried including the glewInit() function from within the draw method, where I am clearing the screen to any number of colors (to verify that gl calls are making it through).
So how, then, am I supposed to get a valid context for glew?
(I'm on Windows, using the Visual C++ compiler.)
-
Here is my code, btw...
main.c
@#define QT_NO_OPENGL_ES_2
#include <QApplication>
#include "glwidget.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GLWidget w;
w.show();return a.exec();
}@glwidget.h
@#ifndef GLWIDGET_H
#define GLWIDGET_H#include <GL/glew.h>
#define QT_NO_OPENGL_ES_2
#include <QGLWidget>class GLWidget : public QGLWidget
{
Q_OBJECTpublic:
explicit GLWidget(QGLWidget *parent = 0);
~GLWidget();QSize minimumSizeHint() const;
QSize sizeHint() const;protected:
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
};#endif // GLWIDGET_H
@glwidget.cpp
@#include "glwidget.h"
GLWidget::GLWidget(QGLWidget *parent) :
QGLWidget(parent)
{
}GLWidget::~GLWidget() {}
QSize GLWidget::minimumSizeHint() const {
return QSize(640, 480);
}QSize GLWidget::sizeHint() const {
return QSize(800, 600);
}void GLWidget::initializeGL() {
GLenum err = glewInit();
if (GLEW_OK != err) {
printf("GLEW error: %s\n", glewGetErrorString(err));
} else {
printf("Glew loaded; using version %s\n", glewGetString(GLEW_VERSION));
}glClearColor(0.2f, 0, 0, 1.0f);
}void GLWidget::resizeGL(int w, int h) {
}void GLWidget::paintGL() {
glClear( GL_COLOR_BUFFER_BIT );
}@ -
Sounds like you have an OpenGL ES 2 build of Qt. You will need to build your own copy of Qt5 configuring with -opengl desktop. Hopefully Qt 5.0.2 will ship with a pre-compiled build against desktop OpenGL too.
Qt 5.1 will also ship with helpers for every OpenGL function which will make it unnecessary to use GLEW. See http://doc-snapshot.qt-project.org/qt5-dev/qtgui/qopenglcontext.html#versionFunctions-2. I will also be blogging about this shortly.
-
That's fantastic news about the pre-built desktop version, and more especially about 5.1! Thanks for the feedback. I took the OpenGL stuff for the project out of Qt for now, but if I get back around to the Qt part before the new versions become available, I will try building it up by hand. Thanks! :)
-
I've done my own build with the desktop OpenGL, and Qt is still missing the function glDrawBuffers(). Can you guys please add it, and any other missing functions? Thanks.
-
Which version did you build?
-
I pulled qt5stable a month or so ago and just built that. Has it been fixed since then?
-
Does your build contain QOpenGLContext::versionFunctions() function? If so just call that to get a pointer to a QOpenGLFunctions_<major>_<minor>[_profile] object. Call initializeOpenGLFunctions on it and use it to call any OpenGL function supported byt that version and profile. See http://www.kdab.com/opengl-in-qt-5-1-part-1 for more info.
-
Mister(or Miss?)ZapB, you said we don't need something like glew in Qt5.1 anymore and I have some questions.
I am new to openGL and I find out I can't use VAO(glGenVertexArrays, glBindVertexArrays etc) in Qt5.0.2 directly.
As the website said "Unfortunately, those functions are not loaded by Qt and they must be accessed using a GL loader library or by manually calling wglGetProcAddress."
"Qt and opengl":http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_Qt
How could we call glGenVertexArrays without the help of GLEW in Qt5.1?
Do Qt5.1 Beta support this?Thanks -
Yes Qt 5.1 supports this either via the QOpenGLFunctions_major_minor_profile classes or through QOpenGLVertexArrayObject helper class. See http://www.kdab.com/opengl-in-qt-5-1-part-2
-
Thanks for your reply. As a beginner, I always find it hard to start with Qt and opengl
Most of the examples are obsolete or do not suit for a beginner like me. It would be appreciated
if there are any resources or tutorials designed for the beginners of opengl who like to use
it with Qt5.I am following the guides of this site "opengl guide":http://www.arcsynthesis.org/gltut/
You have to alter some codes if you want it to work on Qt5 -
Thanks ZapB, when using QOpenGLFunctions_major_minor_profile, drawBuffers is indeed compiled and linked.
Sadly, now nothing works. If it's not one thing with Qt, it's always, always another.
-
Ah, how many hours have I spent sat staring at a black cube on a black background with OpenGL? :) Good luck debugging!
-
Here's the problem, it worked perfectly fine when just deriving from QGLFunctions. Now, when I use the new classes, nothing draws. These classes are not simple replacements for the old ones, nor are they simple replacements for regular OpenGL calls. Sadly, they are advertised as such.
I would really like to see some simple examples or tutorials on using the new classes. Thanks.
-
Found my problem. I needed to set the format to use the compatibility profile to just draw a line.
Non-Qt, OpenGL rant:
I really wish OpenGL wouldn't have taken a chainsaw to the most basic functions of the library. I don't see the point of requiring every single last thing to use a shader program. Sometimes people just want to draw simple primitives without having to set all of that up.