Game Development Reference
In-Depth Information
IDirect3DTexture9* Textures[3] = {0, 0, 0};// texture for each subset
std::ofstream OutFile; // used to dump mesh data to file
Here we have instantiated a pointer to a mesh that we create later. We
also define the number of subsets that the mesh will have—three. In
this example, each subset is rendered with a different texture; the array
Textures contains a texture for each subset, such that the i th index in
the texture array is associated with the i th subset of the mesh. Finally,
the variable OutFile is used to output the contents of the mesh to a
text file. We pass this object to the dump* functions.
The majority of the work for this sample takes place in the Setup
function. We first create an empty mesh:
bool Setup()
{
HRESULT hr = 0;
hr = D3DXCreateMeshFVF(
12,
24,
D3DXMESH_MANAGED,
Vertex::FVF,
Device,
&Mesh);
Here we allocate a mesh with 12 faces and 24 vertices, the amount
needed to describe a box.
At this point, the mesh is empty, so we need to write the vertices
and indices that describe a box to the vertex buffer and index buffer,
respectively. Locking the vertex/index buffer and manually writing the
data easily accomplishes this:
// Fill in vertices of a box
Vertex*v=0;
Mesh->LockVertexBuffer(0, (void**)&v);
// fill in the front face vertex data
v[0] = Vertex(-1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f);
v[1] = Vertex(-1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f);
.
.
.
v[22] = Vertex( 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f);
v[23] = Vertex( 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
Mesh->UnlockVertexBuffer();
Search WWH ::




Custom Search