c++ - 什么时候用 Qt 在 opengl 中创建渲染上下文?

标签 c++ linux qt opengl

我正在使用 Qt 尝试 OpenGL。我编译了2dpainting example来自 Qt 的文档。该示例中有两个并排的动画,一个 native 运行,另一个由 OpenGL 渲染。但我看不出有什么区别。我如何确保使用了硬件加速器。我正在使用 Ångström Linux 的嵌入式设备上运行该示例。

我在 opengl 小部件的构造函数中添加了一行,以确定所使用的渲染器,但该函数始终返回 NULL 指针。

GLWidget::GLWidget(Helper *helper, QWidget *parent)
     : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), helper(helper)
 {
        elapsed = 0;
        setFixedSize(200, 200);
        setAutoFillBackground(false);
        printf("  OpenGL Renderer:   %s\n",glGetString(GL_RENDERER)); //added this line

 }

现在我在许多在线论坛上看到,我需要一个有效的渲染上下文。但这是什么意思?使用 Qt 时它是什么时候创建的?我尝试将相同的函数放入 GLWidget 的所有其他函数中,但没有任何运气。

最佳答案

我相信它会尽可能晚地初始化,即当实际需要绘制某些东西时。

来自QGLWidget::paintEvent()文档:

Handles paint events passed in the event parameter. Will cause the virtual paintGL() function to be called.
The widget's rendering context will become the current context and initializeGL() will be called if it hasn't already been called.

关于c++ - 什么时候用 Qt 在 opengl 中创建渲染上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8139486/

相关文章:

C++11 未定义的函数引用

linux - cygwin编译数学库

qt - 使用原始 OpenGL 调用绘制 Qml 项的问题

c++ - 图元的实现复合模式示例

c++ - Flex Lexer 工具中的类 istream

linux - libdbus-1.so.3 : cannot open shared object file: No such file or directory

php - 使用 SSH 导入 SQL

c++ - 为什么 Qt 资源在 Linux 而不是 Windows 中加载?

c++ - 如何在 OSX 应用程序的标题栏中的 Qt 中添加全屏图标?

c++ - 为什么类的析构函数被调用两次?