OpenGL Shader Language


A shader language operates directly on the graphic microprocessing unit (GPU) on your graphics card. Unlike OpenGL, shader language is a programming language, like c, and can be used to override a lot of the functionality in OpenGL while also extending the functionality. Shaders operates at a lower level than openGL, which means you have more control. Take for example lighting in OpenGL. To a large extent OpenGL provides quite adequate light effects. However if you wish for even more realism then you could develop your own in a shader language, and of cause many people have.

The shader language associated with OpenGL is called OpenGL Shader Langauge (GLSL). In many ways it loooks like Java and even more like C. Once you have written your GLSL code you will use OpenGL commands to pass the code to the GPU where it gets compiled and sits in storage waiting for another OpenGL command to make it active. Of course eventually you will delete your code and place the graphics card back into its default state.

the OpenGL pipeline

So far we have avoided referring much of the detail in the graphics pipeline that is used within OpenGL. When working with GLSL we need to know a little more about it.

The graphics pipeline is the sequence of steps that are taken in your graphics card to draw something on your monitor. The steps go from receiving vertices to generate a geometric shape, process this with textures and lighting, allow for perspective and viewport to eventually produce pixels on the display. There are many other steps to go from vertices too pixels. Below is a diagram crudely illustrating the main steps.

GLSL version 1.5, associated with OpenGL 2.0, permits you to write your own code at two stages of the pipeline.

  1. vertex operations
  2. fragment operations

Version 1.5 has introduced a stage inbetween, geometric operations, which we will not use as it is not available with many graphics cardsat the moment. However the principles remain the same and it will not take you long to adopt geometric operations into your games when they become standard.