[Qt-interest] Overlay in conflict to QPainter?

unimd at web.de unimd at web.de
Fri Jul 23 09:53:20 CEST 2010


I use a NVidia Quadro FX 3800 which supports overlays. But you have to activate this feature in the settings and furthermore I set the exported pixeltypes to RGB-overlays (RGB555 Format).. Usually it is color index based.

In the beginning I thought to use QPainter to draw some 2D text over my 3D context but now I get more and more into QGraphicsView. I am wondering if QGraphicsView solves all my problems. This link is nice: http://doc.trolltech.com/qq/qq26-openglcanvas.html

Btw, thank you Oliver for all the information. I tried using the begin/endNativePainting()-methods but I think it is supposed to help you if you plan to do some OpenGL-stuff between a begin() and end() of a QPainter.. So I agree with you that the paintOverlayGL() function is probably a counter piece to the paintGL()-method. And as I said for just OpenGL render stuff it works fine. :) But QPainter just works inside a paintEvent().. Which is odd.

So another work around would be something like that inside of the paintOverlayGL()-method, e.g.:

 QPixmap pixmap(textWidth, textHeight);
 pixmap.fill(Qt::transparent);
 
 QPainter painter(&pixmap);
 painter.drawText(0, 0, textWidth, textHeight, Qt::AlignCenter | Qt::TextWordWrap, QString("My message..."));

 QImage image = pixmap.toImage();
 QImage glImage = QGLWidget::convertToGLFormat(image);

 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();  
#ifdef QT_OPENGL_ES
 glOrthof(0.0, width(), 0.0, height(), -100.0, 100.0);
#else
 glOrtho(0.0, width(), 0.0, height(), -100.0, 100.0);
#endif

 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
 glPushMatrix();
 glDisable(GL_DEPTH_TEST);
 glEnable(GL_BLEND);
 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

 glRasterPos2i(50, 50);
 glDrawPixels(glImage.width(), glImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits());

 glDisable(GL_BLEND);
 glEnable(GL_DEPTH_TEST);
 glPopMatrix();

Hope that helps others, too...
Cheers and thank you!
___________________________________________________________
Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief!  
Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02



More information about the Qt-interest-old mailing list