在QGLWidget中使用makeCurrent()的地方? [英] Where to use the makeCurrent() in QGLWidget?

查看:3234
本文介绍了在QGLWidget中使用makeCurrent()的地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

qt的文档说:


当paintGL(),
resizeGL ,或initializeGL()被调用。如果你需要从其他地方调用
标准OpenGL API函数(例如在你的窗口小部件的
构造函数或你自己的绘图函数中),你必须首先调用
makeCurrent()。

Your widget's OpenGL rendering context is made current when paintGL(), resizeGL(), or initializeGL() is called. If you need to call the standard OpenGL API functions from other places (e.g. in your widget's constructor or in your own paint functions), you must call makeCurrent() first.

对于以下情况:

paintGL()
{
    drawSomething();
}
...
drawSomething()
{
    glClearColor()...
    //many other gl calls...
}

我必须在 drawSomething c $ c>函数。

do I have to makeCurrent inside the drawSomething() function.

如果我只是使用QPainter调用,而不是标准的OpenGL API函数。我必须使用makeCurrent吗?

And if I only make QPainter call in stead of standard OpenGL API functions. Do I have to use makeCurrent?

推荐答案


do I have to makeCurrent inside the drawSomething() function.

如果该函数仅从 paintGL 调用,将调用 paintGL 与上下文已经是当前的

If that function is called only from paintGL, no, as Qt will call paintGL with the context already current.

正如文档所说,你需要它, GL上下文当前在一些其他函数。

As the docs say, you'll need it whenever you need the GL context current in some other function.

// called from other code, context may not be current
void MyGLWidget::setBackgroundColor(const QColor &color) {
     makeCurrent();
     glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
}

这篇关于在QGLWidget中使用makeCurrent()的地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆