[SOLVED] Mix QPainter with GLWidget displaying OpenGL ES 2.0?
-
Hi,
Edit: Not sure if this is possible or if I'm missing something??
I'm trying to overlay graphics from a QPainter onto a GLWidget with OpenGL ES 2.0 output. I'm using Qt 4.7 (on Maemo 5 / N900)
I've managed this with Qt 4.6.2 but for some reason it only shows a blank screen when I moved to Qt4.7.
Does anyone know of an example of a GLWidget which uses OpenGL ES 2.0 and overlays a QPainter please? I've seen other permutations (e.g. QPainter and non-OGLES2.0) but not yet one that covers OGELS2.0 and a QPainter overlay simultaneously.
I suspect my problem is related to how the two interact and would like to see an overlay example in operation.
I've posted the code I'm using with Qt4.7 below in case it helps understand my problem (it's based on the Qt 'Cube' example). If I remove the QPainter references it displays the 3D model fine.
Thanks in advance.
@
void CMyGLWidget::paintEvent(QPaintEvent *event){QPainter painter;
bool result = painter.begin(this);
painter.beginNativePainting();
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Set modelview-projection matrix
program->setUniformValue("mvp_matrix", projection * matrix);// Tell OpenGL which VBOs to use
glBindBuffer(GL_ARRAY_BUFFER, vboIds[2]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIds[3]);// Offset for position
int offset = 0;// Tell OpenGL programmable pipeline how to locate vertex position data
int vertexLocation = program->attributeLocation("a_position");
program->enableAttributeArray(vertexLocation);
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*NUM_GLFLOAT_PER_VERTEX, (const void *)offset);// Offset for colour
offset += sizeof(GLfloat)*3;// Tell OpenGL programmable pipeline how to locate vertex colour data
int colLocation = program->attributeLocation("ourcolor");
program->enableAttributeArray(colLocation);
glVertexAttribPointer(colLocation, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*NUM_GLFLOAT_PER_VERTEX, (const void *)offset);// Offset for normal
offset += sizeof(GLfloat)*3;// Tell OpenGL programmable pipeline how to locate vertex normal
int normLocation = program->attributeLocation("normal");
program->enableAttributeArray(normLocation);
glVertexAttribPointer(normLocation, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*NUM_GLFLOAT_PER_VERTEX, (const void *)offset);// Enable depth buffer
glEnable(GL_DEPTH_TEST);// Disable back face culling
glDisable(GL_CULL_FACE);if (vert2Dsurf){
glDrawElements(GL_TRIANGLES, numind2Dsurf, GL_UNSIGNED_INT, 0);
}// Unbind the VBOs
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);painter.endNativePainting();
painter.end();
} // End paintEvent()
@ -
I posted the question in a different way and the answer that worked is here: