Good, by now I managed to make it work like this:
{
painter.begin(this);
painter.
setRenderHint(QPainter::Antialiasing);
// Save current OpenGL state
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// Setup OpenGL context.
setBackgroundColor
(QColor(255,
255,
255));
setForegroundColor
(QColor(0,
0,
0));
setFont
(QFont("Helvetica",
18));
glEnable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
drawOpenGL(); // draw a bunch of opengl things
// Restore OpenGL state
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
drawOverPaint(&painter); // 2D QPainter drawing
painter.end();
}
void OpenGLWidget::paintEvent(QPaintEvent *event)
{
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
// Save current OpenGL state
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// Setup OpenGL context.
setBackgroundColor(QColor(255,255,255));
setForegroundColor(QColor(0,0,0));
setFont(QFont("Helvetica", 18));
glEnable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
drawOpenGL(); // draw a bunch of opengl things
// Restore OpenGL state
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
drawOverPaint(&painter); // 2D QPainter drawing
painter.end();
}
To copy to clipboard, switch view to plain text mode
What I don't understand is, on one computer this works perfectly and the QPainter code is drawn over the OpenGL, on another computer the OpenGL is on top of the QPainter drawing and covers it fully.
How do I have control over what gets painted over what?
Bookmarks