Studying DirectX. I connect the z buffer, but it does not work! But then there are curves ugly rippling in the eyes of flicker.

Here are my options

D3DPRESENT_PARAMETERS params; ZeroMemory(&params,sizeof(params)); params.Windowed = true; params.SwapEffect = D3DSWAPEFFECT_DISCARD; params.BackBufferFormat = display.Format; params.BackBufferCount = 3; params.BackBufferWidth = display.Width; params.BackBufferHeight = display.Height; params.EnableAutoDepthStencil = true; params.AutoDepthStencilFormat = D3DFMT_D24X8; params.FullScreen_RefreshRateInHz = display.RefreshRate; params.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL; params.hDeviceWindow = hWnd; 

Render condition

 device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL); device->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW); device->SetRenderState(D3DRS_LIGHTING,TRUE); device->SetRenderState (D3DRS_AMBIENT, 0xaaaaaa); 

And buffer cleaning

 device->Clear( 0, NULL, D3DCLEAR_TARGET| D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); 

Where cant tell me pliz.

2 answers 2

So you clean the Z-buffer with some strange values ​​(colors 0; 0; 255), so you get garbage, because the depth of each point is not compared with some depth, but with the value of color, which is nonsense. Z-buffer is needed for the depth test and in the initial state it must contain such values ​​that any point passes the depth test (for example, 0; 0; 0)

  • one
    I figured out the problem. The problem was the projection matrix. it inadequately responds to setting the position of the front cut-off plane to less than zero. device-> Clear (0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB (0,0,255), 1.0f, 0); and this line clears the buffer and makes the background blue. and there is nothing wrong with that. - alex7249
  • four
    Just do not freak out right away. I just forgot that the value for the depth buffer in clear is passed separately. And there is nothing to be clever. - cy6erGn0m
 //Достаточно одного внеэкранного буфера. params.BackBufferCount = 3; //1 // включаешь стенсил-буфер но в рендере не используешь params.EnableAutoDepthStencil = true;//FALSE //ишь ты, смотри чтобы видеокарта поддерживала этот режим //для этого проверяй CheckDeviceFormat params.AutoDepthStencilFormat = D3DFMT_D24X8; //для оконного режима задай такие настройки params.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; params.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;