GLSL’s gl_Position Variable

The Most Important Variable

Specifies the transformed position of a vertex

Notes

gl_Position is arguably the most important concept for vertex shaders. Its value at the end of a vertex shader’s execution will specify the transformed vertex position, which is closely related to which pixel in the window the vertex maps too.

Every vertex position undergoes a set of transformations, which do a lot of the magic of computer graphics: mapping the 3D world to a 2D grid of pixels; moving, rotating, and changing the size of objects; and simplifying how we navigate and interact with complex 3D scenes. We’ll see the math behind these transformations and build up a rich set of tools to support those operations.

You might be asking, we didn’t do any transformations here, so what’s up? We’ll we did; sort of. It’s like when you multiply a number by one, you get the same number back. Here we didn’t explicitly apply a transformation, but we could have used the identity transform, which is the 3D graphics equivalent to multiplying by one. We’ll see what that transform looks like later, and how we can combine multiple simple transformations to represent complex operations.