How does OpenGL know what data the elements '0,1,2, 2,3,0' refer to in the index buffer? There doesn't appear to be any explicit communication between the vertex buffer and the index buffer, where OpenGL is told that element 0 of the index buffer refers to (1.0F,0.0F) in the vertex buffer, element 1 refers to (1.0F,1.0F), element 3 (0.0F,1.0F) etc...
How, and at what point, does OpenGL 'understand' which elements of the index buffer refer to which vertex of the vertex buffer?
float vertices[]
= {
1.0F,0.0F,
1.0F,1.0F,
0.0F,1.0F,
0.0F,0.0F
};
unsigned short int indices[]
= {
0,1,2,
2,3,0
};
unsigned int VB, IB;
glGenBuffers(1, &VB);
glBindBuffer(GL_ARRAY_BUFFER, VB);
glNamedBufferData(VB, sizeof(vertices),vertices,GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glGenBuffers(1, &IB);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB);
glNamedBufferData(IB, sizeof(indices), indices, GL_STATIC_DRAW);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);