Reputation: 74
I was going to try to optimize my VBOs to use indices instead of just clumping all vertices together but somehow I can't use GL_INDEX_ARRAY. It just says 'Use of undeclared identifier GL_INDEX_ARRAY' and it's not even defined in gl.h (I looked). Is there another way I'm supposed to index my VBOs? I use this code to create my VBOs:
glGenVertexArraysOES(1, &vertexArray);
glBindVertexArrayOES(vertexArray);
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*vertexDataSize, vertexData, GL_STATIC_DRAW);
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 40, BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 40, BUFFER_OFFSET(12));
glEnableVertexAttribArray(GLKVertexAttribColor);
glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, 40, BUFFER_OFFSET(24));
At first I thought there was some GLKVertexAttribIndex but since there wasn't I guessed I was supposed to use glEnableClientState(GL_INDEX_ARRAY); but that doesn't exist apparently. So how am I supposed to use an index array with my VBOs?
Upvotes: 1
Views: 261
Reputation: 8480
Use GL_ELEMENT_ARRAY_BUFFER to indicate an index buffer. Indices are usually defined as a short, so something like:
glGenBuffers(1, &indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLshort)*indexDataSize, indexData, GL_STATIC_DRAW);
Upvotes: 1