How does 'glVertexAttribPointer' bind to a buffer object


I am new to OpenGL and this might be a very basic question which is little confusing.
I am using by aftab munshi to learn the basics and its going well except for one thing on page 123.

How do you bind the buffer object to point to the shader indices using glVertexAttribPointer. I am guessing you need to bind the buffer before you use the glVertexAttribPointer and the last parameter will point to the buffer object instead of the client memory.

But in the text book i am referring

glBindBuffer(GL_ARRAY_BUFFER, vboIds[0]);

glBindBuffer(GL_ARRAY_BUFFER, vboIds[1]);

glBindBuffer(GL_ARRAY_BUFFER, vboIds[2]);

glVertexAttribPointer(VERTEX_POS_INDX, VERTEX_POS_SIZE, GL_FLOAT, GL_FALSE, vtxStrides[0], 0);
glVertexAttribPointer(VERTEX_NORMAL_INDX, VERTEX_NORMAL_SIZE, GL_FLOAT, GL_FALSE, vtxStrides[1], 0);

because the last buffer binded is the vboIds[2] all the 3 glVertexAttribPointer points to this last buffer ??? Isn’t that wrong ?

Or does this mean something
glBindBuffer(GL_ARRAY_BUFFER, vboIds[0]);

Is this binding the buffer object to the the shader indices ? I know what glEnableVertexAttribArray means but does it also bind the buffer to the indices ?

I am using by aftab munshi

Um, the link goes to the OpenGL ES 3.0 programming guide. Which was not written by “Aftab Munshi”. Indeed, searching for that name in conjunction with “OpenGL” led to the fact that the OpenGL ES 2.0 programming guide being written by “Aaftab Munshi” wrote.

In any case, if that really is the verbatim code from that book, stop using it! That book is dangerously wrong, and you should instead move on to pretty much anything else. Your initial understanding was correct, and that book’s code is broken. The three glVertexAttribPointer calls will all be associated with boIds[2]; the prior two bind calls are irrelevant.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.