Game Development Reference
In-Depth Information
Loading and rendering an exported 3D
model
OK, so now we've got the model data exported, how do we go about loading it into
our program and rendering it? It's actually surprisingly easy, as these next sections
will show.
Adding the IwGraphics API to a project
Marmalade's 3D model rendering code is part of the IwGraphics API, so before we
can draw anything we need to add this library to our project. This is done by adding
iwgraphics to the subprojects section of the MKB file.
We then need to add a call to IwGraphicsInit at the start of our program, and
IwGraphicsTerminate at the end. This API relies on both IwGx and IwResManager,
so we must call the initialization functions for both of these APIs before calling the
IwGraphics one.
Loading and accessing an exported 3D model
You've probably already guessed that this is almost trivially easy. The exporter
generated a GROUP file, so all we have to do is load it into memory and then dig the
model out of the resource group. Here's a block of code which does just that:
CIwResGroup* lpCubeGroup = IwGetResManager()->
LoadGroup("Cube/Cube.group");
CIwModel* lpCube = static_cast<CIwModel*>(lpCubeGroup->
GetResNamed("Cube", "CIwModel"));
Or alternatively you could do the following if you don't want to be bothered with
retaining a pointer to the resource group instance:
CIwModel* lpCube = static_cast<CIwModel*>(IwGetResManager()->
GetResNamed("Cube", "CIwModel"));
That's it. The model is now loaded into memory and ready to render.
 
Search WWH ::




Custom Search