To detect the OpenGL version
If you want to enforce a particular OpenGL version
- set the option in software (see code example below)
- for desktop/native, either set the environment variable
QT_OPENGL
to desktop
or set the application attribute to Qt::AA_UseDesktopOpenGL
- for ANGLE, either set the environment variable
QT_OPENGL
to angle
or set the application attribute to Qt::AA_UseOpenGLES
- for software rendering, either set the environment variable
QT_OPENGL
to software
or set the application attribute to Qt::AA_UseSoftwareOpenGL
- create a static build of Qt using the
configure
options to set the implementation of OpenGL you want (but be mindful of the Qt licensing rules)
- for desktop/native, include
-opengl desktop
- for ANGLE, don't include an
-opengl
option; that's because it is the default
- there is also
-opengl dynamic
which lets Qt choose the best option. This was introduced in Qt 5.4. If you want this option but don't need a static build for any other reason, there's no need to create a static build, as the prebuilt binaries use this option since Qt 5.5.
- there are also other variants that you can explore at Qt for Windows - Requirements. Although this is a Windows-specific page, much of the information about configuring OpenGL for Qt is contained here. (Probably because most of the OpenGL rendering issues are on the Windows platform!)
Code example
#include <QGuiApplication>
//...
int main(int argc, char *argv[])
{
// Set the OpenGL type before instantiating the application
// In this example, we're forcing use of ANGLE.
// Do either one of the following (not both). They are equivalent.
qputenv("QT_OPENGL", "angle");
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
// Now instantiate the app
QGuiApplication app(argc, argv);
//...
return app.exec();
}
(thanks to peppe for the initial answers in the comments above and thanks to user12345 for the Blog link)
glGetString(GL_VERSION)
?GL_VERSION
; usingOpenGLInfo
in Qt Quick itself; usingQOpenGLContext::openGLModuleType()
.Qt::AA_UseOpenGLES
before creating a Q(Gui)Application.