Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QGLBuffer

    General and Desktop
    4
    5
    7121
    Loading More Posts
    • 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
      fbucek last edited by

      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 Reply Quote 0
      • T
        Typhlosion last edited by

        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 Reply Quote 0
        • B
          baysmith last edited by

          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 Reply Quote 0
          • N
            nicolauz last edited by

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

            1 Reply Last reply Reply Quote 0
            • N
              nicolauz last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post