Game Development Reference
In-Depth Information
IwGx only supports eight sub-pixel positions per pixel; so to convert our coordinates
to use sub-pixel positioning, all we need to do is multiply the screen coordinates by
eight or use the bitwise shift operator to shift left by three places.
Color streams
If we want to draw a polygon using flat shading, so that every pixel rendered is the
same color, we can just set the ambient color of our material and our work is done.
However, if we want to render a polygon using gouraud shading, we need to specify
a color to be used at each vertex. This can't be done with a material, so we need to
override the material's color information by providing our own color stream.
We do this by creating an array of CIwColour objects, which is Marmalade's chosen
method of representing a color. This class has four public member variables of type
uint8 (an unsigned byte) called r , g , b , and a , which (probably not surprisingly)
represent the red, green, blue, and alpha values of a color.
Note that because Marmalade was developed in the UK, all instances
of the word color in the API will actually be spelled colour .
CIwColour also provide several methods to make setting and manipulating
colors easier.
Returning to the triangle defined in the earlier diagram, if we wanted to color
the top of it red, the bottom-right corner green, and the bottom-left corner blue,
we can use the following code:
CIwColour* c = new CIwColour[3];
c[0].Set(255, 0, 0, 255);
c[1].Set(0 255, 0, 255);
c[2].Set(0, 0, 255, 255);
IwGxSetColStream(c);
Note that IwGxSetColStream does not require us to specify the number of colors
in our stream. This is because IwGx expects to find the same number of colors as
there are vertices. If we do not want to specify a color stream, we can just pass
NULL into the IwGxSetColStream function and the selected material's colors will
be used instead.
 
Search WWH ::




Custom Search