好的。我可以加载网格到我的项目,但我不能改变网格的颜色。在屏幕上,网格的颜色是白色。我想把它改成红色,但我不能。请帮帮忙。
下面是我的代码:
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);
}发布于 2011-11-15 02:58:35
不完全确定D3DUtil_InitMaterial()的作用,但需要为mtrl灯光特性设置正确的值。
float red = 1.0f, green = 0.0f, blue = 0.0f;
mtrl.Diffuse.r = 1.0f;
mtrl.Diffuse.g = 1.0f;
mtrl.Diffuse.b = 1.0f;
mtrl.Ambient.r = red;
mtrl.Ambient.g = green;
mtrl.Ambient.b = blue;
mtrl.Specular.r = 0.5f;
mtrl.Specular.g = 0.5f;
mtrl.Specular.b = 0.5f;
mtrl.Power = 8.0f;
g_pApp->m_pd3dDevice->SetMaterial(&mtrl);漫反射、镜面反射和功率值仅是示例。
https://stackoverflow.com/questions/8126527
复制相似问题