Loading and compiling shaders
A shader is a small program running on the graphics card, which has special computing units for them. Modern GPUs have thousands of shader units to be able to run the shaders in a massively parallel fashion, which is one of the reasons for the high-speed drawing of pictures of 3D worlds.
The OpenGL rendering pipeline uses several shader types, as seen in Figure 2.1, but we will use only two of the types here: vertex shaders and fragment shaders, the first and last steps in the pipeline. There are more shader types, such as geometry or tessellation shaders, and also shaders outside the normal pipeline such as compute shaders, which are used for simple but fast computation in the shader units.
Let’s take a closer look at the two shader types we will use in the OpenGL renderer to draw the objects to the screen: the vertex and fragment shaders.
Vertex and fragment shaders
A vertex shader uses the uploaded vertex data as input and transforms...