PDA

View Full Version : VBOs and glDrawElements() with JOGL



gmseed
12-09-2011, 03:59 AM
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



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_BUFFE R); // 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_BUFF ER); // disable vertex colour array
glv.glDisableClientState(GL2.GL_COLOR_ARRAY); // disable vertex colour array
}

V-man
12-09-2011, 05:06 AM
http://www.opengl.org/wiki/Common_Mistakes:_Deprecated

Also
glEnableClientState(GL2.GL_ELEMENT_ARRAY_BUFFER)
doesn't make any sense.


You can also look at
http://www.opengl.org/wiki/VBO_-_just_examples

and also
http://www.opengl.org/wiki/Vertex_Buffer_Object
http://www.opengl.org/wiki/VBO_-_more

gmseed
12-09-2011, 09:35 AM
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:



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
}