Hi,
I am looking at code from a tutorial that sets up a VBO and draws a static mesh. I noticed that the size of the vertex array is not divisible by three (it is 2904), yet the call to glDrawArrays(GL_TRIANGLES) works. How? Wouldn't that be the same as the immediate mode code I supplied in the #if/#else branch?
See the code at the very bottom.
// Bind our texture in Texture Unit 0
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, Texture);
// Set our "myTextureSampler" sampler to user Texture Unit 0
glUniform1i(TextureID, 0);
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// 2nd attribute buffer : UVs
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
glVertexAttribPointer(
1, // attribute
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// 3rd attribute buffer : normals
glEnableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
glVertexAttribPointer(
2, // attribute
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Draw the triangles !
// Aren't these two methods of rendering specifying the same command?
// vertices.size() = 2904 (capacity=3597)
#if 0
for(int i=0;i<vertices.size();i+=3)
{
for(int j=0;j<3;j++)
{
glBegin(GL_TRIANGLES);
glm::vec3 &v=vertices[i+j];
glm::vec2 &t=uvs[i+j];
glm::vec3 &n=normals[i+j];
glNormal3fv(&n.x);
glTexCoord2fv(&t.x);
glVertex3fv(&v.x);
glEnd();
GLenum err=glGetError(); //1282 = GL_INVALID_OPERATION
}
#else
glDrawArrays(GL_TRIANGLES, 0, vertices.size() ); // Why doesn't this fail.
GLenum err=glGetError(); //Success
#endif