I draw in Direct3D9 models. Took a minimal example. Against the background is a plane with a texture, in front of it is a kettle, created by the function dx. Models are drawn on top of each other. How to draw the models correctly so that the teapot is in front of the plane, and not vice versa? Render code:

void D3DXDevice::PaintModel() { if (this->Device) { Device->Clear(NULL, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, Colors::White, 1, NULL); Device->BeginScene(); Device->SetFVF(Vertex::FVF); // настройки, Ρ‚Π°ΠΌ тСкстуры, Π½ΠΎΡ€ΠΌΠ°Π»ΠΈ ΠΈ ΠΏΡ€ΠΎΡ‡Π΅Π΅ Device->SetStreamSource(0, this->models, 0, sizeof(Vertex)); // this->model - экзСмпляр класса модСль, (Ρ‚Π°ΠΌ всС, ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π», тСкстур, ΠΈ Ρ‚.Π΄.) // отрисовываСм ΠΏΠ»ΠΎΡΠΊΠΎΡΡ‚ΡŒ // сдвигаСм ΠΌΠΈΡ€ΠΎΠ²ΠΎΠ΅ ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΠΎΠ²Π°Π½ΠΈΠ΅ Π½Π° 20 Π΅Π΄ΠΈΠ½ΠΈΡ† Π½Π° нас(ΠΏΠΎ -z) ΠΈ рисуСм Ρ‡Π°ΠΉΠ½ΠΈΠΊ ID3DXMesh* Teapot; D3DXCreateTeapot(Device, &Teapot, 0); D3DXMATRIX trans; D3DXMatrixTranslation(&trans, 0.f, 0.f, -20.f); Device->SetTransform(D3DTS_WORLD, &trans); Teapot->DrawSubset(0); Teapot->Release(); Device->EndScene(); Device->Present(NULL, NULL, NULL, NULL); } } 

I attach a screenshot of the result. What technique should be used to draw everything correctly (I have a model, there are several textures in it, all this needs to be drawn not at once, but when switching materials, you can see in the screenshot how the models shine through each other).

enter image description here

enter image description here

  • one
    Turn on the Z-test (also known as the depth test) - Kromster
  • @Kromster has already found the answer to the question, it was in an erroneous perspective projection matrix. Z-buffer has been enabled. - Range

1 answer 1

Incorrectly set perspective projection matrix, parameters znear and zrear are confused.