How does glDrawArrays know what to draw?
The call to glBindBuffer
tells OpenGL to use vertexBufferObject
whenever it needs the GL_ARRAY_BUFFER
.
glEnableVertexAttribArray
means that you want OpenGL to use vertex attribute arrays; without this call the data you supplied will be ignored.
glVertexAttribPointer
, as you said, tells OpenGL what to do with the supplied array data, since OpenGL doesn't inherently know what format that data will be in.
glDrawArrays
uses all of the above data to draw points.
Remember that OpenGL is a big state machine. Most calls to OpenGL functions modify a global state that you can't directly access. That's why the code ends with glDisableVertexAttribArray
and glBindBuffer(..., 0)
: you have to put that global state back when you're done using it.
DrawArrays takes data from ARRAY_BUFFER
.
Data are 'mapped' according to your setup in glVertexAttribPointer
which tells what is the definition of your vertex.
In your example you have one vertex attrib (glEnableVertexAttribArray) at position 0
(you can normally have 16 vertex attribs, each 4 floats).
Then you tell that each attrib will be obtained by reading 3 GL_FLOATS from the buffer starting from position 0.