Game Development Reference
In-Depth Information
Rendering a polygon
In IwGx, the most commonly used polygon types are lines, triangles, and quads
(basically two triangles that share a common edge).
Also supported are sprites, which are always rectangular in shape and do not
allow any scaling of textures, and n-polys, which can contain up to 63 vertices.
Sprites are rarely used since triangles and quads are more flexible, though they
can be faster to draw especially in software rendering mode. The n-poly can also
be faster to draw for the software renderer than a series of triangles, but they are
generally best avoided since they need to be converted into triangles on the fly in
order to be drawn using hardware rendering.
To render a polygon on screen, we at least need to specify where we want it to
appear on screen and what color we want it to be in. Additionally, we might want
to draw the polygon using a bitmapped image. The following sections show how
we can provide this information.
Materials and textures
First we let IwGx know what color (or indeed colors) and image we want applied
to our polygon. We do this by specifying the material we want to use, which is an
instance of the CIwMaterial class that groups together this information. To set
the material we want to use, we must provide IwGx with a pointer to the relevant
CIwMaterial instance using the following function call:
IwGxSetMaterial(pMaterial);
If we are drawing a polygon with no image applied to it, then the very minimum
information the material will need to provide is the color we want to use.
A material actually contains four different colors that, if you are at all familiar with
3D graphics rendering, you will probably recognize. They are the ambient, diffuse,
emissive, and specular colors. For 2D rendering purposes, it is only the ambient
color that we are concerned with. We'll look into the others when we move on to
3D rendering in Chapter 4 , 3D Graphics Rendering .
The material also specifies the texture we want to apply. A texture specifies a
bitmapped image that we want to apply to our polygon, and is represented in
Marmalade by the CIwTexture class.
The CIwTexture class is actually a wrapper for the CIwImage class that actually
stores the pixel information for an image. CIwTexture adds functionality to control
how the image is actually rendered, with support for enabling and disabling features
such as bilinear filtering and mipmapping.
 
Search WWH ::




Custom Search