Game Development Reference
In-Depth Information
ppEffectInstances —Returns an ID3DXBuffer containing an
array of D3DXEFFECTINSTANCE structures. We ignore this param-
eter for now by specifying 0.
pNumMaterials —Returns the number of materials for the mesh
(that is, the number of elements in the D3DXMATERIAL array out-
put by ppMaterials ).
ppMesh —Returns the created ID3DXMesh object filled with the
XFile geometry
11.2.2 XFile Materials
Argument seven of D3DXLoadMeshFromX returns the number of
materials that the mesh contains, and argument five returns an array of
D3DXMATERIAL structures containing the material data. The D3DX-
MATERIAL structure is defined as follows:
typedef struct D3DXMATERIAL {
D3DMATERIAL9 MatD3D;
LPSTR pTextureFilename;
} D3DXMATERIAL;
It is a simple structure; it contains the basic D3DMATERIAL9 structure
and a pointer to a null-terminating string that specifies the associative
texture filename. An XFile doesn't embed the texture data; rather it
embeds the filename, which is then used as a reference to the image
file that contains the actual texture data. Thus, after we load an XFile
with D3DXLoadMeshFromX , we must load the texture data given the
texture filenames. We show how to do this in the next section.
It is worth noting that the D3DXLoadMeshFromX function loads
the XFile data so that the i th entry in the returned D3DXMATERIAL
array corresponds with the i th subset. Thus, the subsets are labeled in
the order 0, 1, 2, …, n-1 , where n is the number of subsets and mate-
rials. This allows the mesh to be rendered as a simple loop that iterates
through each subset and renders it.
11.2.3 Sample Application: XFile
We now show the relevant code to the first sample of this chapter
called XFile. The sample loads an .x file called bigship1.x that was taken
from the media folder of the DirectX SDK. The complete source code
can be found in the companion files. Figure 11.1 shows a screen shot of
the sample.
Search WWH ::




Custom Search