[Qt-interest] Overlay in conflict to QPainter?
unimd at web.de
unimd at web.de
Tue Jul 20 10:23:56 CEST 2010
Hello everybody,
I am using overlays to render 2D stuff above my 3D-context. To do this I decided to use overlays and render them in the paintOverlayGL()-method. Furthermore I just want to swap the current buffer and not using swapBuffers(). Everything works fine, if I just draw a simple primitive like:
void vmOGLWidgetOverlay::paintOverlayGL()
{
makeOverlayCurrent();
HDC hdc = getDC(); //HDC hdc = GetDC(winId());
int nEntries = 4; // number of entries in palette
COLORREF crEntries[4] = { // entries in custom palette
0x00000000, // black (ref #0 = transparent)
0x000000ff, // red
0x0000ff00, // green
0x00ff0000, // blue
};
// set up the layer palette
wglSetLayerPaletteEntries(hdc, 1, 0, nEntries, crEntries);
// realize the palette
wglRealizeLayerPalette(hdc, 1, TRUE);
glClear(GL_COLOR_BUFFER_BIT);
if( MyCriticalObjectHit == true )
{
glBegin(GL_TRIANGLES);
glIndexi(1);
glVertex2d(0, 0.5);
glVertex2d(-0.5, -0.5);
glVertex2d(0.5, -0.5);
glEnd();
}
// just swap the overlay
wglSwapLayerBuffers(hdc, WGL_SWAP_OVERLAY1);
releaseDC(hdc); //ReleaseDC(winId(), hdc);
}
I use the paintEvent()-method to render my 3D-context which looks something like this:
void vmOGLWidgetOverlay::paintEvent(QPaintEvent *)
{
makeCurrent();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
initSettings();
setupViewport(width(), height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0, 0.0, -10.0);
glRotatef(MyXRot/16.0, 1.0, 0.0, 0.0);
glRotatef(MyYRot/16.0, 0.0, 1.0, 0.0);
glRotatef(MyZRot/16.0, 0.0, 0.0, 1.0);
MyLogo->draw();
glShadeModel(GL_FLAT);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
// just swap the main plane
HDC hdc = getDC();
wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE);
releaseDC(hdc);
}
Now, I would like to use a QPainter to draw some text... But somehow this doesn't work properly:
void vmOGLWidgetOverlay::paintOverlayGL()
{
makeOverlayCurrent();
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QFontMetrics fm(font());
QString message(tr("My Message..."));
int textWidth = fm.width(message);
int textHeight = fm.height();
painter.setPen(Qt::red);
painter.drawText(topLeftPos.x(), topLeftPos.y(), textWidth, textHeight, Qt::AlignCenter | Qt::TextWordWrap, message);
painter.end(); // no auto swap because of setAutoBufferSwap(false); in constructor
if( wglSwapLayerBuffers(hdc, WGL_SWAP_OVERLAY1) == false )
qDebug("no overlay swap");
releaseDC(hdc); //ReleaseDC(winId(), hdc);
}
In my constructor I turn off the following:
setAutoFillBackground(false);
setAutoBufferSwap(false);
But I just can't see my 2D text in the overlay plane..
What am I doing wrong? Is there a problem using QPainter in an overlay plane? I don't understand why it doesn't work properly. Is anyone experienced on that area?
___________________________________________________________
Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail
More information about the Qt-interest-old
mailing list