Game Development Reference
In-Depth Information
Since we are using specular lighting, there is one more thing to do. The material that
is used to render our polygons must have a specular color and power specified. The
material's specular color is used to modulate the global specular color, while the
power value indicates how close the vertex normal must be to the light direction for
the specular highlight to kick in. The power value is a uint8 value and only very low
values (that is, less than 8) produce notable differences in the rendered effect. Here is
the code to illustrate this:
CIwMaterial* lpMaterial = new CIwMaterial;
lpMaterial->SetColSpecular(255, 255, 255);
lpMaterial->SetSpecularPower(3);
The previous examples are just making use of Marmalade's built-in
lighting model since it is easy to use and works well enough for most
needs. However, there is absolutely no reason we have to use this
lighting model, as there is nothing stopping us from generating our
own color stream using whatever lighting algorithm we want to use.
Alternatively we could employ OpenGL ES 2.0 shaders, although
discussion of this particular topic is beyond the scope of this topic.
Model data for the cube
We're going to render a lit cube with a different color on each face, so we need to
provide some data streams for the vertices, colors, and normals, and an index stream
to show how this data should be interpreted by the rendering engine. Since we are
not using textures in this example, there is no need to provide a UV stream.
We also want to be as efficient as possible in our drawing, so our aim is to draw
the entire cube with just a single call to IwGxDrawPrims . To do so we'll need to
have three copies of each vertex (one for each face that the vertex is part of) so we
can assign different colors and normals to it, and we'll also need to specify some
degenerate triangles in our index stream to join all the faces together into one big
triangle strip.
Let's start with the vertex stream. We allocate an array of CIwFVec3 and initialize
it with the vertex data. The cube pivot point will be dead center, so all the vertex
coordinates will have the same magnitude.
const uint32 lVertexCount = 24;
CIwFVec3* v = new CIwFVec3[lVertexCount];
v[0].x = 100.0f; v[0].y = -100.0f; v[0].z = -100.0f;
v[1].x = -100.0f; v[1].y = -100.0f; v[1].z = -100.0f;
v[2].x = 100.0f; v[2].y = 100.0f; v[2].z = -100.0f;
v[3].x = -100.0f; v[3].y = 100.0f; v[3].z = -100.0f;
 
Search WWH ::




Custom Search