How To Render a Reference Grid

GLSL Hacker has a handy object called a grid. A grid is more or less just a collection of lines but that info is not really important. You can use a grid as a reference object when there’s no ground plane in the scene.

To use a grid, you need a grid (obviously), a vertex color GPU program and a camera (a perspective in our code snippet).

The following code shows the initialization of a 100×100 units grid made up of 20×20 segments: