UV and position coords in the same VBO

Now that I’ve finally gotten a VBO and IBO to work, I’m trying to get a simple .bmp texture to display properly. I have my vertex data in a float array of the form

float[] vertices = { x1, y1, z1, u1, v1, x2, y2, z2, u2, v2, etc. }

and I store that in a VBO in the init section, store indices in an IBO, then use glDrawElements() in the draw section to draw everything. Also, in the init section, I load a texture. I know I do that correctly, since when I use glBindTexture, draw a simple triangle using glBegin() and glEnd(), and use glTexCoord to assign uv coords to vertices, it comes out as it should.

My problem is that I can’t seem to move from that to using VBO uv data. I don’t know how to get the code to recognize the u and v floats in the vertex array as uv coordinates, and I can’t get it to apply the texture to the shape I draw using glDrawElements. When I just have glBindTexture followed by the glDrawElements bit to draw the square, I get the same untextured red square as when I don’t have a texture at all, only it’s somewhat darker.

Kopelrativ’s first post here leads me to suspect I need to do something with shaders, but I’m not sure what I need to do with them. What’s the equivalent for glTexCoord when using VBOs and IBOs? How come glDrawElements drew an untextured object just fine without my having to write custom shaders? Can I still use glBindTexture, or do I have to use some kind of Texture Buffer Object?

I’m assuming that you’re using old-style vertex array calls here (if you weren’t you’d know it) so what you need to do is look at glTexCoordPointer and it’s associated EnableClientState (GL_TEXTURE_COORD_ARRAY). Otherwise nothing changes.

I don’t have any glEnableClientState for the glDrawElements, nor do I have a glVertexPointer, and yet the untextured triangles show up fine:

            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBufferObjectIds[0]);
            gl.EnableVertexAttribArray(0);
            gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, (5 * sizeof(float)), new IntPtr(0));
            gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBufferObjectIds[0]);
            gl.DrawElements(OpenGL.GL_TRIANGLES, 6, OpenGL.GL_UNSIGNED_INT, new IntPtr(0));
            gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, 0);
            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, 0);

Is that what you mean by old-style vertex array calls?