Here are a few key points about adding vertex colors to the example:
- Storing the color data in a separate buffer is cleaner than concatenating or interleaving it with the position data. This keeps the data layout simple.
- The vertex shader now has inputs for both the position (vp) and color (vc) attributes.
- The color is passed through as an output (fcolour) to the fragment shader.
- The position is still used to set gl_Position for transformation.
- The color input has to start in the vertex shader because that is where per-vertex attributes like color are interpolated across the primitive before being sampled in the fragment shader. The vertex shader interpolates the color value