Game Development Reference
In-Depth Information
As with vertex streams, all we have to do to specify a set of UV values is allocate
an array of CIwSVec2 , populate the array, and submit it to IwGx. We don't need to
specify the number of UV values we are submitting, as IwGx expects to see the same
number of UVs as there are vertices. Here is some sample code that we might want
to use to apply a texture to a triangle:
CIwSVec2* uv = new CIwSVec2[3];
uv[0].x = IW_GEOM_ONE / 2; uv[0].y = 0;
uv[1].x = 0; uv[1].y = IW_GEOM_ONE;
uv[2].x = IW_GEOM_ONE; uv[2].y = IW_GEOM_ONE;
IwGxSetUVStream(uv, 0);
The second parameter of IwGxSetUVStream indicates which texture the UV values
apply to. If the material we are using only has a single texture, we can just leave this
parameter out entirely as it will default to 0 , but if the material does have a second
texture, we need to supply a UV stream to be used with it by changing the second
parameter of IwGxSetUVStream to 1. This UV stream could be the same as the stream
for the first texture or it could be a completely different set of UV values.
If our material does not have a texture applied to it, there is no need to set the UV
stream to NULL as it will be ignored completely.
Drawing a polygon
We've now seen how to set just about all the information we need to specify how
we want our polygon to appear, so we can finally instruct IwGx to draw it. To do so,
we need to let IwGx know how our various input streams should be interpreted by
using the following function call:
IwGxDrawPrims(polygon_type, indices, num_indices);
The polygon_type parameter indicates whether we are drawing triangles, quads,
lines, sprites, or n-polys, while the indices parameter is an array of uint16 values
showing the order in which the elements of our input streams should be accessed.
This is called an index stream . The num_indices parameter is just a count of how
many elements are in the indices array.
 
Search WWH ::




Custom Search