Game Development Reference
In-Depth Information
Materials also provide control over other polygon rendering features, such as
whether the polygon is rendered flat or gouraud shaded, and how it should be
blended with the current screen contents when it is drawn.
Materials can either be created in code or they can be instanced by the resource
manager. The following sections illustrate this.
Creating materials in code
Creating a material in code requires little more than making a new instance of
CIwMaterial and using the available methods to set the color, textures, and
other settings. For example, to create a material that will render bright red,
semi-transparent polygons we could use the following code:
CIwMaterial* lpRedMaterial = new CIwMaterial;
lpRedMaterial->SetColAmbient(255, 0, 0, 128);
lpRedMaterial->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
Note that Marmalade will raise an assert message if you try to create a local
CIwMaterial instance on the program stack. This happens because rendering
does not happen the moment you make a drawing function call, so by the time
rendering does occur, the material data will likely have been trashed by other
functions reusing the same area of stack space.
Creating materials using an MTL file
While creating materials in code is simple enough, there is an easier way, especially
when it comes to specifying materials with textures. This involves yet another use of
our friend, the ITX file.
A material file has the extension .mtl and again uses the same formatting rules as
an ITX file. We can create any number of CIwMaterial instances in an MTL file and
initialize them with the required colors, textures, and other settings.
As a bonus, any texture we refer to in the MTL file will also be loaded automatically,
meaning we don't have to list it separately in a GROUP file. In order for this to work,
all the source image files must reside in a subdirectory named textures , which is
located in the same directory as the MTL file, or alternatively they must already have
been loaded into memory either from another GROUP file or in the same GROUP file
prior to referencing the MTL file.
Marmalade natively supports the PNG, TGA, GIF, and BMP image
file formats. If you want to load any other type of bitmap, you will
need to provide your own custom resource handler to do so.
 
Search WWH ::




Custom Search