Game Development Reference
Earlier in this chapter, we mentioned how we can set multiple flags in
glClear() , to clear certain buffers. The GL_DEPTH_BUFFER_BIT flag is used
to clear the depth buffer each render call.
Let's go over some of the important OpenGL functions used for a basic lighting and
depth testing system. In each case, there are more options available in the OpenGL
documentation, which can be examined at your leisure.
The glLightfv() function is used to specify the properties of a given light. The
first parameter is used to select which light to edit, the second is used to determine
which property to edit, and the third is used to specify the new value. The first two
parameters must be an enumerator (or enum) corresponding to a specific value.
For instance, the options for the first parameter can be GL_LIGHT0 , GL_LIGHT1 ,
GL_LIGHT2 , and so on. Meanwhile, the second parameter could be GL_AMBIENT ,
GL_DIFFUSE , or GL_SPECULAR to define which lighting property of the given light
to modify, or even GL_POSITION to define its position. As an example, the following
call sets the ambient lighting value of the first (zeroth) light to the value of ambient ,
where ambient is btVector3 representing the ambient color we want:
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
The glEnable() function is a very generic function used to enable certain features
in the OpenGL library. Every feature we enable typically consumes more processing
power, so OpenGL gives us the freedom to enable only what we need. We will
use this function to enable lighting in general ( GL_LIGHTING ), create a single light
( GL_LIGHT0 ), enable the coloring of our primitives ( GL_COLOR_MATERIAL ), and en-
able depth testing ( GL_DEPTH_TEST ).