user1765354
user1765354

Reputation: 357

OpenGL 3.0 Not working with Qt on Windows

I'm working on a Qt project on Windows that heavily uses OpenGL. It was originally configured to use OpenGL version 2.1, and everything worked fine. Recently, I upgraded the OpenGL version in the code to 3.0. Now, the project crashes very early during initialization with the following error:

QML debugging is enabled. Only use this in a safe environment.
ASSERT: "qGuiApp" in file kernel\qopenglcontext.cpp, line 1238
Debug Error!

Program: C:\Qt\5.7\msvc2015_64\bin\Qt5Cored.dll
Module: 5.7.0
File: global\qglobal.cpp
Line: 3063

ASSERT: "qGuiApp" in file kernel\qopenglcontext.cpp, line 1238

... and this is the line that the debugger stops on:

if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {

In global.cpp, it's failing at the end of this block. Specifically, the line number given in the error message corresponds to the #endif line:

#ifndef QT_NO_EXCEPTIONS
/*
   \internal
   Allows you to call std::terminate() without including <exception>.
   Called internally from QT_TERMINATE_ON_EXCEPTION
*/
Q_NORETURN void qTerminate() Q_DECL_NOTHROW
{
    std::terminate();
}
#endif

Looking at qopenglcontext.cpp, line 1238 is actually within a large comment block. Here is the code that directly follows, which is almost certainly the right place based on the error message above (the Q_ASSERT(qGuiApp) line):

QOpenGLContext::OpenGLModuleType QOpenGLContext::openGLModuleType()
{
#if defined(QT_OPENGL_DYNAMIC)
    Q_ASSERT(qGuiApp);
    return QGuiApplicationPrivate::instance()->platformIntegration()->openGLModuleType();
#elif defined(QT_OPENGL_ES_2)
    return LibGLES;
#else
    return LibGL;
#endif 
}

Keep in mind these are standard Qt files and this is code I have never touched.

Here is a summary of what I've tried so far. Of course, none of these worked:

I'm out of ideas here. Any suggestions or knowledge would be welcome. Also, if you need more information please ask and I will respond promptly.

EDIT : Here is the beginning of main:

int main(int argc, char* argv[]) 
{ 
   // setup OpenGL before application initialization 
   GLFunctions::setupOpenGL(); 
   QApplication app(argc, argv);
   ....
}

And here is the setup function:

static void setupOpenGL()
{
    QSurfaceFormat fmt; 
    fmt.setDepthBufferSize( 24 ); 
    if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) 
    { 
        fmt.setVersion(3, 3); 
        fmt.setProfile(QSurfaceFormat::CoreProfile); 
        //fmt.setRenderableType(QSurfaceFormat::OpenGL); 
    } 
    else 
    { 
        fmt.setVersion(3, 0); 
    }
}

Upvotes: 0

Views: 1223

Answers (1)

Darklighter
Darklighter

Reputation: 2192

From the documentation of QOpenGLContext::openGLModuleType():

Note: This function requires that the QGuiApplication instance is already created.

You may set your desired version regardless of the openGLModuleType (remove the check) and check later if you got your requested version or not.

Upvotes: 1

Related Questions