0

I'm making a game for iOS using GLKit (OpenGL ES 2), and would like to use VBOs and VAOs as I think they would increase performance quite a lot (and Instruments is recommending it when I test my app in it).

I have a lot of textured objects that don't actually change position, size, texture etc, so I would assume VBOs would help.

At the moment I am using arrays of GLKVector2 to store vertex and texture coordinate data, and I'm not quite sure how to go from here to VBOs.

Can anyone help with this?

Cheers, Nick.

Nick Duffell
  • 340
  • 1
  • 6
  • 17

1 Answers1

0

You can pass them directly to glBufferData (), like this:

GLKVector2    objects[k];
// ... Fill out your objects vertices in objects
GLuint buffer = 0;
glGenBuffers (1, &buffer);
glBindBuffer (GL_ARRAY_BUFFER, buffer);
glBufferData (GL_ARRAY_BUFFER, sizeof (objects), objects, GL_STATIC_DRAW);
glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer (2, GL_FLOAT, sizeof (GLKVertex2), 0);

This tell OpenGL to generate a buffer and bind it. glBufferData() actually uploads it to the card. The call to glVertexPointer () says where you want to start pulling vertices from in the array. The pointer in the last parameter becomes an offset when you're using VBOs.

EDIT: Sorry - filled in some details. Had a brain fart. See here for details.

user1118321
  • 25,567
  • 4
  • 55
  • 86