Game Development Reference
In-Depth Information
Once a light is registered, we can turn it on and off using what this next
example illustrates:
Device->LightEnable(
0, // the element in the light list to enable/disable
true); // true = enable, false = disable
5.5 Sample Application: Lighting
The sample for this chapter creates the scene shown in Figure 5.7. It
demonstrates how to specify vertex normals, how to create a material,
and how to create and activate a directional light. Note that in this sam-
ple program we do not make use of the d3dUtility.h/cpp material and
light functionality code because we want to show how it is done manu-
ally first. However, the rest of the samples in this topic do use the
material and light utility code.
Figure 5.7: Screen shot from
the LitPyramid sample
The steps for adding light to a scene are:
1. Enable lighting.
2. Create a material for each object and set the material before ren-
dering the corresponding object.
3. Create one or more light sources, set the light sources, and enable
them.
4. Enable any additional lighting states, such as specular highlights.
First we instantiate a global vertex buffer that stores the pyramid's
vertices:
IDirect3DVertexBuffer9* Pyramid = 0;
The Setup function contains all the code relevant to this chapter, so
we omit the other functions to save space. It implements the previously
discussed steps to add lighting to a scene. The Setup method starts by
Search WWH ::




Custom Search