I have managed to load a mesh in DirectX 10 and I am now trying to load another mesh but whenever I add a new mesh the original mesh disappears. How can I display two meshes at the same time? This is a section of the code I have tried so far (I can post more code if needed):
const D3D10_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = sizeof( layout ) / sizeof( layout[0] );
// Create the input layout
D3D10_PASS_DESC PassDesc;
g_pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
V_RETURN( pd3dDevice->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature,
PassDesc.IAInputSignatureSize, &g_pVertexLayout ) );
// Set the input layout
pd3dDevice->IASetInputLayout( g_pVertexLayout );
// Load the mesh
V_RETURN( g_Mesh.Create( pd3dDevice, L"Tiger\\tiger.sdkmesh", true ) );
V_RETURN( g_Mesh.Create( pd3dDevice, L"Wing\\wing.sdkmesh", true ) );
// Initialize the world matrices
D3DXMatrixIdentity( &g_World );
Rendering the mesh:
//
// Render the mesh
//
UINT Strides[1];
UINT Offsets[1];
ID3D10Buffer* pVB[1];
pVB[0] = g_Mesh.GetVB10( 0, 0 );
Strides[0] = ( UINT )g_Mesh.GetVertexStride( 0, 0 );
Offsets[0] = 0;
pd3dDevice->IASetVertexBuffers( 0, 1, pVB, Strides, Offsets );
pd3dDevice->IASetIndexBuffer( g_Mesh.GetIB10( 0 ), g_Mesh.GetIBFormat10( 0 ), 0 );
D3D10_TECHNIQUE_DESC techDesc;
g_pTechnique->GetDesc( &techDesc );
SDKMESH_SUBSET* pSubset = NULL;
ID3D10ShaderResourceView* pDiffuseRV = NULL;
D3D10_PRIMITIVE_TOPOLOGY PrimType;
for( UINT p = 0; p < techDesc.Passes; ++p )
{
for( UINT subset = 0; subset < g_Mesh.GetNumSubsets( 0 ); ++subset )
{
pSubset = g_Mesh.GetSubset( 0, subset );
PrimType = g_Mesh.GetPrimitiveType10( ( SDKMESH_PRIMITIVE_TYPE )pSubset->PrimitiveType );
pd3dDevice->IASetPrimitiveTopology( PrimType );
pDiffuseRV = g_Mesh.GetMaterial( pSubset->MaterialID )->pDiffuseRV10;
g_ptxDiffuseVariable->SetResource( pDiffuseRV );
g_pTechnique->GetPassByIndex( p )->Apply( 0 );
pd3dDevice->DrawIndexed( ( UINT )pSubset->IndexCount, 0, ( UINT )pSubset->VertexStart );
}
}
The code is doing exactly what you asked it to do:
If you want both meshes loaded at the same time, you need to use two different instances of whatever
g_Meshis--which I'm guessing is theSDKmesh.cpp/SDKMesh.hhelper stuff from those old samples.