Game Development Reference
In-Depth Information
With the type of light taken care of, we set the color of light using the function call
IwGxSetLightCol . There are two versions of this function. Both take the ID of the
light we wish to modify, but the RGB color of the light can either be specified as
three uint8 values for red, green, and blue, or a pointer to a CIwColour instance
can be supplied instead.
The following code sets the light with ID zero to be an ambient light with a
mid-grey color:
IwGxSetLightType(0, IW_GX_LIGHT_AMBIENT);
IwGxSetLightCol(0, 128, 128, 128);
Now let's create a diffuse light with a specular highlight. We'll need two additional
functions to do this, IwGxSetLightSpecularCol to set the color of the specular
highlight, and IwGxSetLightDirn to set the direction in which the light is pointing.
The direction is specified as a unit vector in terms of world space coordinates. Here's
some code to illustrate this:
CIwFVec3 lLightDir(1000.0f, 0.0f, 1000.0f);
lLightDir.Normalise();
IwGxSetLightType(1, IW_GX_LIGHT_DIFFUSE);
IwGxSetLightCol(1, 128, 128, 128);
IwGxSetLightSpecularCol(1, 200, 200, 200, 255);
IwGxSetLightDirn(1, &lLightDir);
This code snippet sets up the light ID one to be a diffuse light with mid-grey
intensity and a brighter grey specular highlight. The light is pointing at a 45 degree
angle between the x and z axes of the world.
Our lights have now been initialized, so all that is left to do is let Marmalade know
we want to switch them on! There are a number of functions available to allow us
to do this. We can either use IwGxLightingOn and IwGxLightingOff to enable or
disable all the initialized light sources, or we can enable each part of the lighting
model independently. The following example code disables emissive lighting but
enables ambient, diffuse, and specular lighting:
IwGxLightingAmbient(true);
IwGxLightingDiffuse(true);
IwGxLightingEmissive(false);
IwGxLightingSpecular(true);
 
Search WWH ::




Custom Search