Never mind, it seemed to have shown the view count after the first post.
Anybody?
Well.. I could not still separate those two, but I decided to make use of goto, even though it's not recommended.
Here's the code for multiple objects I came up with:
void LoadXFileStatic(LPCSTR filename, int ObjNum)
{
static LPD3DXBUFFER * materialBuffer = new LPD3DXBUFFER[ObjectQuantity];
static DWORD * numMaterials = new DWORD[ObjectQuantity]; // Note: DWORD is a typedef for unsigned long
static LPD3DXMESH * mesh = new LPD3DXMESH[ObjectQuantity];
if (FirstLoad[ObjNum] == FALSE)
{
goto Render;
}
// Load the mesh from the specified file
HRESULT hr=D3DXLoadMeshFromX(filename, D3DXMESH_SYSTEMMEM,
d3ddev, NULL,
&materialBuffer[ObjNum],NULL, &numMaterials[ObjNum],
&mesh[ObjNum] );
if(S_OK != hr) // Check to determine whether method failed
{
MessageBox(NULL,
"Failed to load one of the Objects",
"Error!",
MB_ICONERROR | MB_OK);
}
static D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)materialBuffer[ObjNum]->GetBufferPointer();
static D3DMATERIAL9 *meshMaterials = new D3DMATERIAL9[numMaterials[ObjNum]];
static LPDIRECT3DTEXTURE9 *meshTextures = new LPDIRECT3DTEXTURE9[numMaterials[ObjNum]];
for (DWORD i=0; i < numMaterials[ObjNum]; i++)
{
// Copy the material
meshMaterials[i] = d3dxMaterials[i].MatD3D;
// Set the ambient color for the material (D3DX does not do this)
meshMaterials[i].Ambient = meshMaterials[i].Diffuse;
// Create the texture if it exists - it may not
meshTextures[i] = NULL;
if (d3dxMaterials[i].pTextureFilename)
{
D3DXCreateTextureFromFile(d3ddev, d3dxMaterials[i].pTextureFilename, &meshTextures[i]);
}
}
materialBuffer[ObjNum]->Release();
Render:
for (DWORD i=0; i < numMaterials[ObjNum]; i++)
{
// Set the material and texture for this subset
d3ddev->SetMaterial(&meshMaterials[i]);
d3ddev->SetTexture(0,meshTextures[i]);
// Draw the mesh subset
mesh[ObjNum]->DrawSubset( i );
}
FirstLoad[ObjNum] = FALSE;
}
Nope, I need to figure something out. The rest of the objects use the textures of the first object.
Perhaps a multidimensional array will do the trick..