Why my material of the back mesh cover the front in D3D9

0

image

image

image

image

As above images, I created two rectangles by D3DXCreateMeshFVF, but the material of the back(Yellow) cover the front(Red). what is the reason??

some code:

Material Set:

void SetMeshMaterial(D3DMATERIAL9 & mt, UINT r, UINT g, UINT b, UINT a)
{
    ZeroMemory(&mt, sizeof(D3DMATERIAL9));
    mt.Diffuse = D3DXCOLOR(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
    mt.Ambient = D3DXCOLOR(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
    mt.Specular = D3DXCOLOR(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
    mt.Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
    mt.Power = 5.0f;
}

Light:

D3DLIGHT9 light;
::ZeroMemory(&light, sizeof(light));
D3DXVECTOR3 direction(1.0, 0.0, 0.0);
D3DXCOLOR d3dcolor = D3DCOLOR_XRGB(255, 255, 255);
light.Type = D3DLIGHT_DIRECTIONAL;
light.Direction = direction;
light.Ambient = d3dcolor;
light.Diffuse = d3dcolor;
light.Specular = d3dcolor;

m_pDevice->SetLight(0, &light);
m_pDevice->LightEnable(0, true);

Render:

m_pDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
m_pDevice->BeginScene();
//////////////////////////////
m_pDevice->SetMaterial(&mt1);
pMesh1->DrawSubSet(0);

m_pDevice->SetMaterial(&mt2);
pMesh2->DrawSubSet(0);

m_pDevice->EndScene();
m_pDevice->Present(NULL, NULL, NULL, NULL);
material
directx-9
cover
asked on Stack Overflow Oct 26, 2018 by wangjs

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0