有几种方式可以让Qt使用OpenGL:桌面(本地)、ANGLE、ES...现在还有“动态”的方式可以在运行时选择。在应用程序中,有没有一种方法可以检测正在使用哪种方式?可以在C++或QML中进行检测吗?
例如,类似于全局声明的东西,让您可以检测操作系统。
例如,类似于全局声明的东西,让您可以检测操作系统。
检测OpenGL版本:
OpenGLInfo
QOpenGLContext::openGLModuleType()
glGetString(GL_VERSION)
如果要强制使用特定的OpenGL版本:
QT_OPENGL
设置为desktop
或将应用程序属性设置为Qt::AA_UseDesktopOpenGL
QT_OPENGL
设置为angle
或将应用程序属性设置为Qt::AA_UseOpenGLES
QT_OPENGL
设置为software
或将应用程序属性设置为Qt::AA_UseSoftwareOpenGL
configure
选项创建Qt的静态构建,以设置所需的OpenGL实现(但要注意Qt许可证规则)
-opengl desktop
-opengl
选项;这是因为它是默认值-opengl dynamic
,它让Qt选择最佳选项。这是在Qt 5.4中引入的。如果您想使用此选项,但无需出于任何其他原因创建静态构建,则无需创建静态构建,因为自Qt 5.5以来的预构建二进制文件都使用此选项。#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();
}
(感谢 peppe 提供的上面评论中的初始答案,以及感谢user12345提供的博客链接)
glGetString(GL_VERSION)
? - genpfaultGL_VERSION
;在Qt Quick中使用OpenGLInfo
;使用QOpenGLContext::openGLModuleType()
。 - peppeQt :: AA_UseOpenGLES
。 - peppe