[Qt-interest] Overlay in conflict to QPainter?

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Thu Jul 22 16:30:33 CEST 2010


unimd at web.de wrote on Thursday, July 22, 2010 11:12 AM:

> ...
> But still I don't understand why Qt provides the function 'void
> QGLWidget::paintOverlayGL()' if I can't use a QPainter for 2D stuff
> inside of this function... I haven't even seen an example using this
> method at all. 

The original intent of paintOverlayGL() is that you call GL commands inside that method - just like you would do in the paintGL()  method. Qt makes sure that there exists a /current/ GL context when it calls paintGL() respective paintOverlayGL().

I have never studied the "overlay" examples in Qt too much, mostly because they always claimed that my cheap 3D graphics card (or the driver thereof) did not support real overlay support, so I never bothered to investigate. Hence I have no experience yet with "mixing" QPainter and real GL calls.

However I remember a blog in the "Qt Labs" about intermixing QPainter and GL calls (which potentially disturb each other's "state machine"), so a new API QPainter::beginNativePainting() was introduced in Qt 4.6.

This is the acticle: http://labs.trolltech.com/blogs/2010/01/06/qt-graphics-and-performance-opengl/ (the mixing part is somewhere at the bottom, "Mixing QPainter and Native OpenGL").

Also I had a quick look at the provided GL examples from Qt 4.6, "overpainting", and it seems that all QPainter related calls are triggered from within

  GLWidget::paintEvent(QPaintEvent *event)

so I am not sure if the same technique is supposed to work from within paintGL() respective paintOverlayGL().

Just to make sure: you did at least "embrace" your QPainter calls in a

  // OpenGL painting here
  ...
  QPainter painter(this);
  ...
  // painting goes here
  ...
  painter.end(); // end of painting

right?

But according to above article I understand that should nowadays even read like:

  // OpenGL painting here
  ...
  QPainter painter(this);
  painter.beginNativePainting();
  ...
  // painting goes here
  ...
  painter.endNativePainting(); // end of "native" painting

But again, not sure whether that is supposed to work within paint(Overlay)GL() or not. In fact, I just realised that the "overlay" example has gone from the Qt 4.6.1 example collection, hasn't it? I remember there existed at least two examples, "overlay" and "overlay2" (implementing a "software" overlay, whereas "overlay" was trying to fetch the graphic card's "hardware" GL overlay). Or was that Qt 3.3.x I am talking about now? ;)

Good luck,
  Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list