[Interest] Mixing OpenGL and QPainter in QOpenGLWidget

Jan Müller 217534 at gmail.com
Thu Mar 2 20:52:05 CET 2017


Hello,

When I use both OpenGL rendering and QPainter calls in the paintGL function
of a QOpenGLWidget class, I get an OpenGL error code (1282) when checking
glGetError().

The painting still works, i.e. what I want to draw correctly appears on the
screen.

Also, this error code only appears on MacOSX. On Linux, it works fine.

Should I be concerned about that error code? It does not feel good and I'm
really thinking there should not be any error at all in the OpenGL
rendering.

I'm mainly concerned about this error, because I have a larger, more
complex application where I use multiple QOpenGLWidgets and switch between
them (through a QStackedLayout) and there the whole window 'flickers' and
misbehaves (i.e. does not render correctly). It is hard to search for
OpenGL errors in my larger application, because I always get this 1282
error code, like I get it in the simple example shown below.


I made a minimal example, just creating and showing a widget derived from
QOpenGLWidget in main(). The code is here:

https://gist.github.com/anonymous/625e69dd61f0685c1cae625bdefbac74

In the widget, I reimplemented initializeGL, resizeGL, paintGL.

The paintGL function looks like this:

void paintGL() {
    qDebug() << "Error 1:" << glGetError();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
    glColor3f(1.0f, 0.0, 0.0);
    glVertex3f(-0.5f, -0.5f, 0);
    glColor3f(0.0, 1.0f, 0.0);
    glVertex3f(0.5f, -0.5f, 0.0);
    glColor3f(0.0, 0.0, 1.0);
    glVertex3f(0.0, 0.5f, 0);
    glEnd();

    QPainter p(this);
    p.setPen(Qt::red);
    p.drawLine(rect().topLeft(), rect().bottomRight());
    qDebug() << "Error 2: " << glGetError();
}

Strangely, the output I get is this:

Error 1: 0
Error 2: 0
Error 1: 1282
Error 2: 0
Error 1: 1282
Error 2: 0

So the first time, no error happens but the second time, there is an error.
When I comment out QPainter and its two calls, the error code is "gone"
(always 0). But when I comment out the OpenGL calls but keep the QPainter
statements, the error is still there.

Do I miss something? Any ideas how to debug? Should I be concerned about
that error code or should I just ignore it? Could it be (one of the)
sources of my more substantial OpenGL errors in my larger application?

I'm using Qt 5.7. And as I've said, it only seem to appear on MacOSX.

Thanks for any feedback!


Best,
  Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170302/32bf8ac9/attachment.html>


More information about the Interest mailing list