Original Post
Hey all, I was wondering if you could help me with this, I am trying to load an .x file as a terrain, however whenever i try to load it i receive an "unhandled exception" error, I've based the code from directtutorial.com so it looks like it should work to me. The .x file is here if anyone wants to try loading it in their own program to see if its valid (I've tested it in the SDK viewer and it looks ok to me) anyway the model doesn't have any textures and it should look like this when its loaded...
so thats what its supposed to look like, the code to load my file looks like: Thats it to load, I know its pretty much ripped from the tutorial but i have to hack this together very quickly. Anyway once its loaded this is the source to render it: And thats it... Am i missing something? If you want to look at the rest of the source, the most recent build is here feel try to test it.
so thats what its supposed to look like, the code to load my file looks like: [source lang = "cpp"]
void CRendering::LoadFromXFile(LPDIRECT3DDEVICE9 gD3dDevice)
{
HRESULT hr=D3DXLoadMeshFromX ("maze.X", D3DXMESH_SYSTEMMEM, gD3dDevice, NULL, &materialBuffer, NULL, &numMaterials, &maze);
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)materialBuffer->GetBufferPointer();
D3DMATERIAL9 *meshMaterials = new D3DMATERIAL9[numMaterials];
for (DWORD i=0; i<numMaterials; i++)
{
// Copy the material
meshMaterials = d3dxMaterials.MatD3D;
// Set the ambient color for the material (D3DX does not do this)
meshMaterials.Ambient = meshMaterials.Diffuse;
}
materialBuffer->Release ();
}
[source lang= "cpp"]
void CRendering::RenderXFile(LPDIRECT3DDEVICE9 gD3dDevice)
{
for (DWORD i=0; i<numMaterials; i++)
{
// Set the material and texture for this subset
gD3dDevice->SetMaterial(&meshMaterials);
// Draw the mesh subset
maze->DrawSubset( i );
}
}