Your application can send arbitrary per-vertex attributes to the vertex shader. We'll start with just a 2D position. OpenGL renders only the parts of triangles which fall in the cube extending from -1 to 1 on all three axes (centered at 0). It defaults to a right-handed coordinate system with the x-axis pointing to the right, the y-axis pointing up, and the z-axis pointing out of the screen toward you.
Our vertex shader converts the 2D position into a 4D one, since OpenGL takes 3D vertices with a 1 tacked onto the end as a fourth coordinate. The fourth coordinate allows us to implement translations as a matrix multiplication. It also allows perspective projections (where objects need to be scaled down as they get farther away) since OpenGL will divide x, y, and z by the fourth coordinate (“w”) at the end.
The fragment shader sets every pixel to the same color.
Then the program clears the framebuffer to a dark blue and executes the shader with the position data.
<< [Index] [Sharing Vertices] >>