Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Problem with Vertex Buffer/Index Buffer Combination [Qt 4.8, C++]

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2012
    Location
    Bavaria
    Posts
    2

    Problem with Vertex Buffer/Index Buffer Combination [Qt 4.8, C++]

    Hello,
    I have the problem, that when I use Vertex Buffer Array in combination with Index Buffer Arrays, nothing appears on the screen. If I'm using only a Vertex Buffer Array, that works fine. I uploaded the project: example_VertexAttrib.zip (works with Qt 4.8 and above)

    My Header includes both arrays:
    Code :
        QVector<float> vertices_;
        QVector<short> indices_;

    I'm initializing both arrays in the Constructor:
    Code :
        /* Push back all vertices */
        vertices_.reserve(16);
        vertices_
                << -1 << -1 << -1     // a 0
                << 1 << -1 << -1      // b 1
                << 1 << 1 << -1      // c 2
                << -1 << 1 << -1       // d 3
     
                << -1 << -1 << 1       // e 4
                << 1 << -1 << 1       // f 5
                << 1 << 1 << 1       // g 6
                << -1 << 1 << 1;    // h 7
     
        /* Push back all indices */
        indices_.reserve(16);
        indices_
                << 0 << 1 << 2 << 3      // front
                << 4 << 5 << 6 << 7      // rear
                << 1 << 5 << 6 << 2      // right
                << 4 << 0 << 3 << 7;    // left

    Buffer Objects are prepared inside QGLWidget::initializeGL()
    Code :
    static const int VERTICES = 0;
    static const int INDICES = 1;
     
        // -- Buffer Objects --
        GLuint bufferObjectVertices;
        GLuint bufferObjectIndices;
     
        QGLFunctions::glGenBuffers(1, &bufferObjectVertices);
        QGLFunctions::glGenBuffers(1, &bufferObjectIndices);
     
        QGLFunctions::glBindBuffer(GL_ARRAY_BUFFER, bufferObjectVertices);
        QGLFunctions::glBufferData(GL_ARRAY_BUFFER, vertices_.size() * sizeof(float), &vertices_.front(), GL_STATIC_DRAW);
     
        QGLFunctions::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjectIndices);
        QGLFunctions::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_.size() * sizeof(short), &indices_.front(), GL_STATIC_DRAW);
     
        QGLFunctions::glVertexAttribPointer(VERTICES, 3, GL_FLOAT, false, 0, 0);
        QGLFunctions::glEnableVertexAttribArray(VERTICES);
     
        GLuint programId = shaderProg_.programId();
     
        QGLFunctions::glBindAttribLocation(programId, VERTICES, "Vertex");

    And I'm trying to draw them inside QGLWidget:aintGL()
    Code :
    glDrawElements(GL_QUADS, indices_.size(), GL_SHORT, 0);
    Attached Files Attached Files

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Did you check if all is OK? Did you use glGetError()?

    http://www.opengl.org/wiki/Common_Mistakes#glGetError
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2012
    Location
    Bavaria
    Posts
    2
    Good idea. I fixed it (it was an invalid enum). Instead of
    Code :
    glDrawElements(GL_QUADS, indices_.size(), GL_SHORT, 0);

    I wrote

    Code :
    glDrawElements(GL_QUADS, indices_.size(), GL_UNSIGNED_SHORT, 0);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •