trouble with VBOs

Hi all, just started moving my rendering code from VAs to VBOs and i’m having some problems with them.

heres the relevent chunk of code:



//decide whether to use VA or VBO
if(Globals.useVertexBufferObjects)
{
            gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, vboHandle);
            gl.glVertexPointer(3,GL.GL_FLOAT,0,BufferUtils.bufferOffset(0));
}
else
            gl.glVertexPointer(3,GL.GL_FLOAT,0,vertBuffer);

//Draw base terrain
        
gl.glDrawElements(GL.GL_TRIANGLES,uvIndices.length,GL.GL_UNSIGNED_INT,uvIndices);

//Draw all the appropriate terrain texture layers.

gl.glEnableClientState(GL.GL_COLOR_ARRAY);

gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glColor4f(1.0f,1.0f,1.0f,0.5f);

gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
gl.glEnable(GL.GL_COLOR_MATERIAL);

gl.glTexCoordPointer(2, GL.GL_FLOAT,0,uvBuffer);
GeoTerrainType tempType;
for(c1 = 0;c1 < terrainTypes.size() ;c1 ++)
{
            tempType = (GeoTerrainType)terrainTypes.get(c1);
                  if(!tempType.isDrawable()) continue;
                  gl.glBindTexture(GL.GL_TEXTURE_2D, tempType.texture.getTextureID());
                           gl.glColorPointer(4,GL.GL_UNSIGNED_BYTE,0,tempType.byteColorBuffer);
                  gl.glDrawElements(GL.GL_TRIANGLES,uvIndices.length,GL.GL_UNSIGNED_INT,uvIndices);
}
gl.glPopAttrib();

gl.glDisableClientState(GL.GL_COLOR_ARRAY);

if(Globals.useVertexBufferObjects) 
{
            gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB,0);
}

First of all, this works perfectly with the VA codepath instead of the VBO codepath (ie Globals.useVertexBufferObjects is false) . When i switch to the VBO codepath however, the first glDrawElements call works correctly (the ‘base terrain draw’ above) but then the second one fails with an EXCEPTION_ACCESS_VIOLATION.

If there was something wrong with any of the mem buffers then the VA codepath wouldn’t work, If something was wrong with the VBO allocation then the first DrawElements call would fail so i’m at a bit of a loss. The only thing i can think of is maybe when you’re using the same VBO multiple times on the same bind you have to reset it in some way ? I can’t find any literature on this tho …

Any ideas ?

D.

and incidentally, just previewing the post there, why on earth did the forum software stick a space in between ‘uv’ and ‘Indices’ in the drawElements calls ???

Binding the vertex buffer object changes the semantics of all *Pointer calls. Your calls to glTexCoordPointer and glColorPointer need to take buffer offsets into the global buffer object. Additionally you should make sure you’re enabling the client state GL_TEXTURE_COORD_ARRAY. I don’t know whether it’s possible to use a vertex buffer object for one *Pointer call and a vertex array for other *Pointer calls.

[quote]Binding the vertex buffer object changes the semantics of all *Pointer calls. Your calls to glTexCoordPointer and glColorPointer need to take buffer offsets into the global buffer object. Additionally you should make sure you’re enabling the client state GL_TEXTURE_COORD_ARRAY. I don’t know whether it’s possible to use a vertex buffer object for one *Pointer call and a vertex array for other *Pointer calls.
[/quote]
The puzzling thing is that it works perfectly for the first DrawElements call. IE if i comment out the second DrawElements call the terrain sphere will be drawn correctly taking its vertex data from the VBO and the texture and UV data from the relevent VAs. I also tried commenting out the colorPointer stuff for the subsequent passes but it still threw the same error.

very confusing ???

I’m searching for relevent stuff on GameDev and OpenGL.org but to no avail yet.

D.

[quote]Binding the vertex buffer object changes the semantics of all *Pointer calls. Your calls to glTexCoordPointer and glColorPointer need to take buffer offsets into the global buffer object. Additionally you should make sure you’re enabling the client state GL_TEXTURE_COORD_ARRAY. I don’t know whether it’s possible to use a vertex buffer object for one *Pointer call and a vertex array for other *Pointer calls.
[/quote]
Actually, that WAS the problem. I was making all my other *Pointer calls before i bound the buffer in the case of the first drawElements call. Then before the SECOND call I was making those texCoordPointer and colorPointer calls which was screwing everything up. I’ll just have to wrap them up in VBOs aswell i guess. Thanks for the help.

D.