Using QPainter and OpenGL together issues
I have been having a moderate of amount of success understanding QT. But I've run into a problem with mixing QPainter and openGL.
I have written just a simple OpenGL renderer that compiles a simple vertex/fragment program. It draws a spinning textured cube. I then wanted to see some QPainter elements be drawn on top of the view and everything has stopped working.
So here's the main rendering code:
@void MainGL::paintEvent(QPaintEvent* event)
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Calculate model view transformation
viewMatrix.translate(0.0, 0.0, -5.0);
m_program.setUniformValue("mvp_matrix", m_projection * viewMatrix);
// painter.setFont(QFont("Arial", 30));
// painter.drawText(rect(), Qt::AlignCenter, "Hello World!");
I've disabled the QPainter code except the painter.beginNativePainting() portion.
My guess is, when I wrap the OpenGL code between the painter.beginNativePainting()/painter.endNativePainting(); that something is happening to my openGL context that I'm not sure what to do.
You will notice I am binding the shader. I know that if this were a full-blown rendering pipeline, I would need to be sure my context was properly maintained. If I comment out the QPainter code, everything draws fine.
What am I missing here?