OK.
I can load mesh into my project, but I can’t change the mesh’s color.
On the screen, the mesh’s color is white.
I want to change it to red, but I can’t.
Please help.
Here is my code:
g_pApp->m_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pApp->m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
g_pApp->m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
g_pApp->m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);
g_pApp->m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
g_pApp->m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
g_pApp->m_pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
g_pApp->m_pd3dDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
D3DMATERIAL9 mtrl;
D3DUtil_InitMaterial(mtrl,1,1,1);
for(int j = 0 ; j < m_meshTarget[i].dwNumMaterial ; j++){
if( m_meshTarget[i].pnTextureIndex[j] != -1){
g_pApp->m_pd3dDevice->SetTexture(0, m_meshTarget[i].ppTexture[m_meshTarget[i].pnTextureIndex[j]]);}
else
g_pApp->m_pd3dDevice->SetTexture(0,0);
g_pApp->m_pd3dDevice->SetMaterial(&mtrl);
m_meshTarget[i].pMesh->DrawSubset(j);
}
Not exactly sure what
D3DUtil_InitMaterial()does, but you need to set proper values formtrllight properties.The diffuse, specular, and power values are just for example.