Original Post
I am trying to render a .x file in my engine and there is a problem that i cant seem to nail down. when i render the mesh and it goes through the rendering pipeline the result is an all black mesh. i ran it through PIX and it seems like all of my diffuse values are 0 which i suspect is the problem. whats confusing the hell out of me is that the materials diffuse is not 0, its actually 0.8. i have no idea whats going on, is there some other diffuse value that the D3DXMesh could be grabbing? if anyone has any information or suggestions please let me know! here are some debugging screenshots PIX Screenshot material values Black model rendering here is all my x model loading / rendering code
#include "XModel.h"
bool CXModel::LoadData(ILoad * pLoadData)
{
if (!static_cast<CXLoadModel *>(pLoadData)->m_szFileName)
return false;
//buffer for loading materials
LPD3DXBUFFER pMatBuffer;
D3DXMATERIAL *pMatPtr;
HRESULT res;
res = D3DXLoadMeshFromX(static_cast<CXLoadModel *>(pLoadData)->m_szFileName, D3DXMESH_MANAGED, GEAR_RENDER_DEVICE, 0,
&pMatBuffer, 0, &m_nNumMaterials, &m_pMesh);
if (res == S_OK)
{
//get material pointer
pMatPtr = (D3DXMATERIAL *)pMatBuffer->GetBufferPointer();
//create material array
m_pMaterials = new D3DMATERIAL9[m_nNumMaterials];
//create tex array
m_ppTexArray = new LPDIRECT3DTEXTURE9[m_nNumMaterials];
//fill out material array
for (DWORD i = 0; i < m_nNumMaterials; i++)
{
m_pMaterials = pMatPtr.MatD3D;
m_pMaterials.Ambient = m_pMaterials.Diffuse;
m_ppTexArray = 0;
if (pMatPtr.pTextureFilename)
D3DXCreateTextureFromFile(GEAR_RENDER_DEVICE, pMatPtr.pTextureFilename, &m_ppTexArray);
}
pMatBuffer->Release();
return true;
}
else
return false;
}
void CXModel::ReleaseData()
{
m_pMesh->Release();
for (DWORD i = 0; i < m_nNumMaterials; i++)
{
if (m_ppTexArray)
m_ppTexArray->Release();
}
delete[] m_ppTexArray;
delete[] m_pMaterials;
}
void CXModel::Draw(CAppearance *pAppearance)
{
int stage = 0;
for (DWORD i = 0; i < m_nNumMaterials; i++)
{
GEAR_RENDER_DEVICE->SetMaterial(&m_pMaterials);
GEAR_RENDER_DEVICE->SetTexture(0, m_ppTexArray);
//pAppearance->BindData(0, stage);
m_pMesh->DrawSubset(i);
}
}