[Interest] Mixing OpenGL and QPainter in QOpenGLWidget

Boudewijn Rempt boud at valdyas.org
Fri Mar 3 09:45:28 CET 2017


Sounds like you're running into the
OSX-only-supports-core-profile-so-qpainter-on-opengl-widget-doesn't-work
bug. That got fixed last summer by Julian Thijssen during his
summer-of-code project and the patch has been merged for Qt 5.9.

https://codereview.qt-project.org/#/c/166202/
https://bugreports.qt.io/browse/QTBUG-33535

Boud


On Thu, 2 Mar 2017, Jan Müller wrote:

> 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
> 

-- 
Boudewijn Rempt | http://www.krita.org, http://www.valdyas.org


More information about the Interest mailing list