Reputation: 4459
The qt's documentation said:
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.
for the following case:
paintGL()
{
drawSomething();
}
...
drawSomething()
{
glClearColor()...
//many other gl calls...
}
do I have to makeCurrent inside the drawSomething()
function.
And if I only make QPainter call in stead of standard OpenGL API functions. Do I have to use makeCurrent?
Upvotes: 1
Views: 4127
Reputation: 22734
do I have to makeCurrent inside the drawSomething() function.
If that function is called only from paintGL
, no, as Qt will call paintGL
with the context already current.
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());
}
Upvotes: 4
Reputation: 22168
As the documentation states:
[The] rendering context is made current when paintGL() ... is called
So there is no need to call makeCurrent
in any method called from paintGL. When using QPainter, it is also not necessary (Btw.: QPainter does not necessarily use OpenGL).
Upvotes: 1