Qt使用OpenGL进行渲染

7

我正在为嵌入式平台开发一款QML应用程序,其中包括一个包含图像的GridView小部件。对于我来说,重要的是滚动GridView时顺畅,并且不会给CPU带来负载。我可以期待Qt使用OpenGL来渲染GridView吗?


据我所知,Qt QML 可以使用着色器(在 Qt 网站上有示例)... 我猜涉及了一些 OpenGl 渲染。 - Thomas Vincent
着色器将随QtQuick 2.0(Qt 5.0)一起提供,或者您可以使用QtQuick3D。 - blakharaz
3个回答

5

我遇到了同样的问题。

QApplication::setGraphicsSystem(QLatin1String("opengl"));

这个方法对我没有用。所以我将OGWidget设置为视口:

QDeclarativeView mainwindow;
mainwindow.setSource(QUrl::fromLocalFile("./qml/app.qml"));
QGLFormat format = QGLFormat(QGL::DirectRendering); // you can play with other rendering formats like DoubleBuffer or SimpleBuffer
format.setSampleBuffers(false);
QGLWidget *glWidget = new QGLWidget(format);
glWidget->setAutoFillBackground(false);
mainwindow.setViewport(glWidget);

不要忘记在*.pro文件中添加OpenGL。

你使用的是哪个Qt版本? - Mohsen Zahraee
这是当时的最新版本。如果我没记错的话,是带有qtquick 1.0的4.6版本。 - avida

3

根据您使用的平台

QApplication::setGraphicsSystem(QLatin1String("opengl"));

或者(Symbian)
QApplication::setGraphicsSystem(QLatin1String("openvg"));

在实例化QApplication对象之前。

2

默认情况下,Qt不使用OpenGL渲染后端。您可以通过使用QGlWidget来强制使用它。在您的情况下,由于您想要使用一个现成的小部件,您可以将渲染后端设置为命令行选项:

<binary name> -graphicssystem opengl

"graphicssystem"选项已从Qt5中删除。 - Color

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接