Ok I'm trying for like 2 hours to find out why the shader doesn't get color information when the mesh definitily has color information.
I've imported a 3ds model file (palm) into 3ds max 2010.
Then I've exported that model with pandasofts X file export plugin.
Now when I view this model in the DirectX Viewer it looks like this:
As you can see it clearly HAS colors and I don't think that these are textures.
But when I load it in my engine I'm always getting this Error:
Direct3D9: (ERROR) :Vertex shader function usage (D3DDECLUSAGE_COLOR,0) does not have corresponding usage in the current vertex declaration
Which means that the shader does not get any color information which totally confuses me because it does have color.
Well look at my code at tell me what's wrong please :(
VertexDeclaration:
const D3DVERTEXELEMENT9 declarationColoredMesh[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
{0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
D3DDECL_END()
};
HRESULT CMesh::InitializeVertexDeclaration(LPDIRECT3DDEVICE9EX device)
{
// Create VertexDeclaration
if(FAILED(device->CreateVertexDeclaration(declarationTexturedNormalMesh, &m_pD3DVertexDeclTextureNormal)))
{
MessageBox(NULL, L"Failed to create VertexDeclaration", L"CreateVertexDeclaration() - HRESULT", MB_OK);
return E_FAIL;
}
if(FAILED(device->CreateVertexDeclaration(declarationColoredMesh, &m_pD3DVertexDeclColored)))
{
MessageBox(NULL, L"Failed to create VertexDeclaration", L"CreateVertexDeclaration() - HRESULT", MB_OK);
return E_FAIL;
}
return S_OK;
}
Mesh Creation:
HRESULT CMesh::LoadCharacterMesh(LPDIRECT3DDEVICE9EX device, LPCWSTR MeshLocation)
{
if(FAILED(D3DXLoadMeshFromX(MeshLocation,
D3DXMESH_SYSTEMMEM,
device,
NULL,
&m_pD3DMaterialBuffer,
NULL,
&m_dwNumberOfCharacterMaterials,
&m_pD3DMeshCharacter)))
{
MessageBox(NULL, L"Failed to load mesh from file", L"D3DXLoadMeshFromX() - HRESULT", MB_OK);
return E_FAIL;
}
// extract Material information from the X file Buffer to our own Material buffer
D3DXMATERIAL* pMaterials = (D3DXMATERIAL*)m_pD3DMaterialBuffer->GetBufferPointer();
m_pD3DMeshCharacterMaterials = new D3DMATERIAL9[m_dwNumberOfCharacterMaterials];
m_pD3DMeshCharacterTextures = new LPDIRECT3DTEXTURE9[m_dwNumberOfCharacterMaterials];
for(DWORD i = 0; i < m_dwNumberOfCharacterMaterials; i++)
{
// copy the material
m_pD3DMeshCharacterMaterials = pMaterials.MatD3D;
// Set ambient color for materials
m_pD3DMeshCharacterMaterials.Ambient = m_pD3DMeshCharacterMaterials.Diffuse;
// Create texture for mesh (if it exists)
m_pD3DMeshCharacterTextures = NULL;
if(pMaterials.pTextureFilename)
{
if(FAILED(D3DXCreateTextureFromFileA(device, pMaterials.pTextureFilename, &m_pD3DMeshCharacterTextures)))
{
MessageBox(NULL, L"Failed to create Texture from file", L"D3DXCreateTextureFromFile() - HRESULT", MB_OK);
return E_FAIL;
}
}
}
m_pD3DMaterialBuffer = NULL;
return S_OK;
}
Mesh Rendering:
void CMesh::RenderCharacterMesh(LPDIRECT3DDEVICE9EX device)
{
device->SetVertexDeclaration(m_pD3DVertexDeclColored);
for(DWORD i = 0; i < m_dwNumberOfCharacterMaterials; i++)
{
device->SetMaterial(&m_pD3DMeshCharacterMaterials);
device->SetTexture(0, m_pD3DMeshCharacterTextures);
m_pD3DMeshCharacter->DrawSubset(i);
}
}