Initializing GLEW: "Missing GL Version"
-
While initializing glew in a class that inherits QWindow I get the error "Missing GL Version" after creating a QOpenGLContext, and glGetString(GL_VERSION) returns an empty string. Is this the correct way to initialize glew? Here is my code:
@#include "gl/glew.h"
#include "glviewwindow.h"
#include <QSurfaceFormat>
#include <QOpenGLContext>
#include <QDebug>
#include "qopengl.h"GLViewWindow::GLViewWindow(QWindow* parent)
: QWindow(parent),
context(new QOpenGLContext)
{
setSurfaceType(OpenGLSurface);
}GLViewWindow::~GLViewWindow()
{
delete context;
delete format;
}void GLViewWindow::initWindowOpengl()
{
#ifdef QT_DEBUG
format = new QSurfaceFormat(QSurfaceFormat::DebugContext);
#else
format = QSurfaceFormat();
#endif
format->setMajorVersion(3);
format->setMinorVersion(3);
format->setProfile(QSurfaceFormat::CoreProfile);
format->setSwapBehavior(QSurfaceFormat::DoubleBuffer);
format->setRenderableType(QSurfaceFormat::OpenGL);
setFormat(*format);
context->setFormat(requestedFormat());
if(!context->create())
qDebug() << "context creation failed";
if(!context->isValid())
qDebug("Opengl context invalid!");
context->makeCurrent(this);
qDebug() << this->format->majorVersion() << "." << this->format->minorVersion();
qDebug() << context->format().majorVersion()<< "." << context->format().minorVersion();glewExperimental = GL_TRUE; GLenum err = glewInit(); if(err != GLEW_OK) { QString s = reinterpret_cast<const char*>(glewGetErrorString(err)); qDebug() << s; qDebug() << reinterpret_cast<const char*>(glGetString(GL_VERSION)); }
}@
-
I just realized that Qt has an class that contains all the opengl functions for a specified version, which gets rid of the need for glew, however, when I call initializeGLFunctions I get an assert at line 257 of qopenglfunctions_3_3_core.cpp. Looking at this section of the source code it seems like initializeGLFunctions is getting the currently bound context, and this is invalid. When I create my context it is valid and I call makeCurrent, but when I call QOpenGLContext::currentContext immediately afterwards I get 0.