Using the Buffer as Input

The vertexAttribPointer tells OpenGL how to load data from the array buffer into the attribute.

103                 function bindBuffer(buffer, attribute, size, type, stride, offset)
104                 {
105                     // Lookup a shader attribute location
106                     var vertexPositionLocation = gl.getAttribLocation(program, attribute);
107                     // enable that attribute (location) to receive data from an array
108                     // The vertexPositionBuffer, defined above, is used because it is the currently bound buffer.
109                     gl.enableVertexAttribArray(vertexPositionLocation);
110                     // Each element in the vector contains size floating point entries, they should not be normalized,
111                     // there are stride bytes between the start of successive attribute values.and the first element is at position
112                     // offset in the array.
113                     gl.vertexAttribPointer(vertexPositionLocation, size, gl.FLOAT, false, stride, offset);
114                 }
(0,1) (-1,-1) (1,-1)

Notes

First, lookup the index of the attribute by name with gl.getAttribLocation.

Then enable the attribute for input by passing that index to gl.enableVertexAttribArray.

Finally, vertexAttribPointer describes exactly how to map the currently bound buffer to the attibute.

As we will soon see, it is common to put values for more than one attribute into a buffer. With more than one attribute in the same buffer, the stride and offset become very important.