Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGLBuffer
Qt 6.11 is out! See what's new in the release blog

QGLBuffer

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 7.8k 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.
  • F Offline
    F Offline
    fbucek
    wrote on last edited by
    #1

    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->create();

    m_vertexBuffer->bind();
    m_vertexBuffer->setUsagePattern(QGLBuffer::StaticDraw);
    m_vertexBuffer->allocate(vertices.constData(), vertices.count());

    glEnableClientState(GL_VERTEX_ARRAY);

    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.

    glPushMatrix();
    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.
    //checkGLError();
    glDisableClientState(GL_VERTEX_ARRAY);
    glPopMatrix();
    glEndList();

    return list;
    @

    Do you have any idea what can be wrong.

    Thank you very much.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Typhlosion
      wrote on last edited by
      #2

      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...

      1 Reply Last reply
      0
      • B Offline
        B Offline
        baysmith
        wrote on last edited by
        #3

        Try changing
        @
        m_vertexBuffer->allocate(vertices.constData(), vertices.count());
        @
        to
        @
        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.

        Nokia Certified Qt Specialist.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nicolauz
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nicolauz
            wrote on last edited by
            #5

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

            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