Hello I am having trouble figuring out why does passing the first element of an array of GLfloat positions (xyz) suddenly give the buffer all the elements of that array.
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * vertices.size(), &vertices, GL_STATIC_DRAW);
vertices is a
std::vector<Vertex>. Since it is, that means that
&vertices is of type
std::vector<Vertex>*, or a pointer to the vector.
However, OpenGL doesn't want a vector. OpenGL was written for C, which has no notion of vectors. Therefore, it expects a C-style array. (If you're not sure what that is, see here.)
According to the C++ standard, a
std::vector must store all of its elements in continuous memory. That means that
vertices must come right after
vertices, and so forth. This is essentially exactly what C-style array is: a pointer to a continuous set of items.
vertices is the first element of the vector, then
&vertices is a pointer to the first element. Like I said above, all elements are stored continuously, so
&vertices is really just a pointer to a C-style array.
In C++11, you can instead use
vertices.data(), which is essentially the same thing but cleaner.