Reputation: 296
I am working on a OpenGL 2.0 renderer (https://bitbucket.org/mattiascibien/anima-render) and I actually came across smething I cannot understand at all which is the stride for the glVertexPointer() instruction. Actually my code looks like this
glBindBuffer(GL_ARRAY_BUFFER, data.vertex_buffer);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(
3,
GL_FLOAT,
sizeof(GLfloat)*3,
(void*)0
);
but I actually found that by reading OpenGL documentation the stride should actually be 0. Changing it does not change how the model is rendered.
What value is correct? Why does changing this parameter makes no difference?
EDIT: the data is stored in a
std::vector<GLFloat>
same happens with glTexCoordPointer using sizeof(GLfloat)*2 or 0
Upvotes: 0
Views: 264
Reputation: 37033
https://www.opengl.org/sdk/docs/man2/xhtml/glInterleavedArrays.xml gives more infos about it.
If stride is 0, the aggregate elements are stored consecutively. Otherwise, stride bytes occur between the beginning of one aggregate array element and the beginning of the next aggregate array element.
while you are providing a stride, that is 0
or your "struct" size (3*sizeof(GLFloat)) this is the same. Yet I'd go with 0 in this case.
Upvotes: 2
Reputation: 434
Stride is the distance from the beginning of one entity, to the beginning of the following entity. 0 is special: it means the distance from the end of one entity to the beginning of the next entity is 0. So basically 0 is the same as sizeof(entity).
Basically they packed 2 different mechanisms in one parameter, which I find suboptimal.
Upvotes: 1