Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] Mix QPainter with GLWidget displaying OpenGL ES 2.0?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Mix QPainter with GLWidget displaying OpenGL ES 2.0?

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 1 Posters 4.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yalnte
    wrote on last edited by
    #1

    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()
    @

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      yalnte
      wrote on last edited by
      #2

      I posted the question in a different way and the answer that worked is here:

      http://developer.qt.nokia.com/forums/viewthread/11633/

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved