Exception using index buffers.

Here is the code I tried to use by reading some tutorials:

from init function

      
                ...
                vaVertices = BufferUtil.newFloatBuffer(m_vertices.length);
		vaVertices.put(m_vertices, 0, m_vertices.length);
		vaVertices.rewind();

		m_VBO_verts = BufferUtil.newIntBuffer(m_indices.length);
		m_VBO_verts.put(m_indices, 0, m_indices.length);
		m_VBO_verts.rewind();
		
		gl.glGenBuffersARB(1, m_VBO_verts);
		gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, m_VBO_verts.get());
		gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB, m_vertices.length * Float.SIZE,
					       vaVertices, GL.GL_STATIC_DRAW_ARB);

and more in the draw function


...
		gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, m_VBO_verts.get());
		gl.glVertexPointer(3, GL.GL_FLOAT, 0, null); 
		
		gl.glDrawArrays(GL.GL_TRIANGLES, 0, m_vertices.length);
...

and I get this exception:


Exception in thread "Thread-3" javax.media.opengl.GLException: javax.media.opengl.GLException: array vertex_buffer_object must be disabled to call this method

Am I doing something wrong?

When mapping C opengl calls to JOGL there was a convention that was held to handle calls taking pointers (e.g. glVertexPointer):
In opengl, glVertexPointer (and the other pointer calls) have two different meanings. If no vbo is bound, then the original C call took a pointer to the data source. If a vbo was bound, the number was an offset in bytes into the bound vbo.

In jogl, this became two different methods, one that takes a Buffer (representing the call when no vbo was bound) and one that takes an int (representing the byte offset when a vbo was bound). When you call glVertexPointer with null, you’re calling the jogl method that expects no bound vbo, however, you want to be calling glVertexPointer with a value of 0 instead (in C, NULL was evaluated as 0 which is misleading in many of the beginner tutorials).

Ok thanks, but now I get a different exception when I change the null to 0.

Exception in thread "Thread-3" javax.media.opengl.GLException: javax.media.opengl.GLException: array vertex_buffer_object must be enabled to call this method

Now it says I have to enable the buffer. It looks like I haven’t bound the indecies to any buffer (except the m_VBO_verts which, I think, is overriden by glGenBufferARB). So how would I do that?

When you call glDrawElements, or glDrawArrays you need to enable the types of pointer arrays used in the rendering. These include vertices, vertex colors, normals, and texture coordinates. Because they may not always be necessary, there are method calls to enable/disable their use.

I noticed you haven’t called glEnableClientState(…) with the correct args to set up your pointers. I can’t remember the specifics but my best advice is to download the opengl specification and read the section on vertex arrays. It’s pretty straight forward and will help to fill in many of the details that most tutorials tend to leave out.

I’m not sure if this is what causes your exception to be thrown, but it is definitely a bug with your drawing code. If the exception persists, posting the entire stack trace will help identify which method call failed.