Skip to content

Instantly share code, notes, and snippets.

@mousebird
Created August 7, 2013 22:25
Show Gist options
  • Save mousebird/6179433 to your computer and use it in GitHub Desktop.
Save mousebird/6179433 to your computer and use it in GitHub Desktop.
// Set up the vertex array (note this can only be done on the main thread)
- (void)makeVertexArray
{
// Create a vertex array object and set up its internal state
glGenVertexArraysOES(1, &_vertexArray);
glBindVertexArrayOES(_vertexArray);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
// Normally you'd have to do this each time
// Vertex arrays encapsulate this for you
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3,
GL_FLOAT, GL_FALSE,
_vertexSize, BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3,
GL_FLOAT, GL_FALSE,
_vertexSize, BUFFER_OFFSET(12));
if (_hasTextureCoords)
{
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2,
GL_FLOAT, GL_FALSE,
_vertexSize, BUFFER_OFFSET(24));
}
glBindVertexArrayOES(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment