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: VBOs and glDrawElements() with JOGL

  1. #1
    Intern Newbie
    Join Date
    Jul 2008
    Posts
    40

    VBOs and glDrawElements() with JOGL

    Hi

    When I use VBOs with glDrawArrays() it works fine. However, when I use glDrawElements() instead I keep getting the following exception:

    element vertex_buffer_object must be disabled to call this method

    at the glDrawElements() call.

    Does anyone have a solution to this highly confusing aspect of VBOs?

    PS. I am using JOGL and don't know if the problem arises due to the versions of glIndexPointer() and glDrawElements() called.

    Thanks

    Graham

    Code :
            if (mIsUsingVertexIndices)
            {
                IndexTriMesh3D triMesh = (IndexTriMesh3D)mGeometricObject;
                int numberTriangles = triMesh.numberTriangles();
                int numberIndices = 3 * numberTriangles;
     
                glv.glEnableClientState(GL2.GL_VERTEX_ARRAY);           // enable vertex arrays
                glv.glEnableClientState(GL2.GL_ELEMENT_ARRAY_BUFFER);   // enable vertex indices
                glv.glEnableClientState(GL2.GL_COLOR_ARRAY);            // enable colour arrays
     
                glv.glBindBuffer(GL2.GL_ARRAY_BUFFER,mVBO);
                glv.glVertexPointer(3, GL.GL_FLOAT, 0, 0);              // set the vertex pointer
     
                glv.glBindBuffer(GL2.GL_ARRAY_BUFFER,mVBOColours);
                glv.glColorPointer(3, GL.GL_FLOAT, 0, 0);
     
                glv.glIndexPointer(GL2.GL_UNSIGNED_INT, 0, mVertexIndices);
                glv.glDrawElements(GL2.GL_TRIANGLES, numberIndices, GL.GL_UNSIGNED_INT, mVertexIndices); 
     
                glv.glDisableClientState(GL2.GL_VERTEX_ARRAY);          // disable vertex arrays
                glv.glDisableClientState(GL2.GL_ELEMENT_ARRAY_BUFFER);  // disable vertex colour array
                glv.glDisableClientState(GL2.GL_COLOR_ARRAY);           // disable vertex colour array
            }

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: VBOs and glDrawElements() with JOGL

    ------------------------------
    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
    Intern Newbie
    Join Date
    Jul 2008
    Posts
    40

    Re: VBOs and glDrawElements() with JOGL

    Hi

    Thanks for your reply and the links. I've now got it working. The error was in allocating the size of the indices buffer.

    My working code block is now:

    Code :
            if (mIsUsingVertexIndices)
            {
              IndexTriMesh3D triMesh = (IndexTriMesh3D)mGeometricObject;
              int numberTriangles = triMesh.numberTriangles();
              int numberIndices = 3 * numberTriangles;
     
              glv.glEnableClientState(GL2.GL_VERTEX_ARRAY);           // enable vertex arrays
              glv.glEnableClientState(GL2.GL_COLOR_ARRAY);            // enable colour arrays
     
              glv.glBindBuffer(GL2.GL_ARRAY_BUFFER,mVBO);
              glv.glVertexPointer(3, GL.GL_FLOAT, 0, 0);              // set the vertex pointer
     
              glv.glBindBuffer(GL2.GL_ARRAY_BUFFER,mVBOColours);
              glv.glColorPointer(3, GL.GL_FLOAT, 0, 0);
     
              glv.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, mVBOIndices);
              glv.glDrawElements(GL2.GL_TRIANGLES, numberIndices, GL.GL_UNSIGNED_INT, 0); // note: the total number of indices
     
              glv.glDisableClientState(GL2.GL_VERTEX_ARRAY);          // disable vertex arrays
              glv.glDisableClientState(GL2.GL_COLOR_ARRAY);           // disable vertex colour array
            }

Posting Permissions

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