• Hello, I have problem with QGLBuffer. I did not find any example so I do not know how exactly it works.

    In this example I am drawing some tria elements, which is working correctly when QGLBuffer is NOT used.

    When I use QGLBuffer, function glDrawElements causes application to crash.

    It looks like array copied to buffer is different from source.

    This is the fragment of code.

    GLuint list = glGenLists(1);
    glNewList(list, GL_COMPILE);

    GLfloat faceColor[4];
    faceColor[0] = qtGreen.redF();
    faceColor[1] = qtGreen.greenF();
    faceColor[2] = qtGreen.blueF();
    faceColor[3] = qtGreen.alphaF();

    m_vertexBuffer = new QGLBuffer(QGLBuffer::VertexBuffer);

    m_vertexBuffer->allocate(vertices.constData(), vertices.count());


    glVertexPointer(3, GL_FLOAT, 0, 0); // THIS IS NOT WORKING - glDrawElements cause app to crash.
    // glVertexPointer(3, GL_FLOAT, 0, vertices.constData()); // THIS IS WORKING PERFECTLY glDrawElements draws elements as intended.

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, faceColor);
    glDrawElements(GL_TRIANGLES,m_count, GL_UNSIGNED_INT, m_index.constData()); // AFTER CALLING THIS FUNCTION APP CRASHES ( when i use QGLBuffer.

    return list;

    Do you have any idea what can be wrong.

    Thank you very much.

  • Do not forget to release the GLBuffer when you don't need it anymore.
    But I am having issues with this QGLBuffer too.
    Any working example would be fine...

  • Try changing
    m_vertexBuffer->allocate(vertices.constData(), vertices.count());
    m_vertexBuffer->allocate(vertices.constData(), vertices.count() * sizeof(GLfloat));

    The second argument to "allocate":http://doc.qt.nokia.com/4.7/qglbuffer.html#allocate expects the number of bytes of space required, not the number of vertices.

  • i just stumbled of the same problem.
    Have you found a solution?

  • never mind ... i used setAttributeArray instead of using setAttributeBuffer

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.