   Enabling ZBuffer causes nothing to be drawn
  I am having problems with my Z-buffer.  When I enable it nothing is drawn to the screen, but when it is disabled, everything is drawn as expected.  I clear the Z-buffer each frame with the value 1.0f.  I am successfully creating a 24-bit Z-buffer with an 8-bit stencil buffer.  I have tried other sizes too, such as a 16-bit Z-buffer and I get the same results.  I know that the problem is not the znear/zfar in my projection matrix because (a) zNear = 1.0f, and (b) I see exactly what I expect when the z-buffer is not enabled.The following code is used to setup the Z-buffer after the device is created (all these values are defaults anyway):device.RenderState.ZBufferEnable = true;device.RenderState.ZBufferFunction = Compare.LessEqual;device.RenderState.ZBufferWriteEnable = true;Any suggestions on what to do to fix this?Edit: I'm using MDX.  Someday I will be updating to SlimDX but there is a lot of code to convert, and I have a really hard time believing that MDX is so bad that Z-buffers don't work at all.   
  try changing your depth test so it accepts greater than. Do you still get nothing?My first guess would be that all your depths are bigger than 1.0f. Unfortunately, in dx9, you can't clear anything to a higher value due to random stupidity. So you could implement it backwards: output farplace-depth, and switch your depth. ;  @harveypekarDefine "random stupidity" for me, pleaase.@OPWhat is your value for zfar? What is the placement and position of your objects you are trying to render? 1.0f is the correct value to clear the depth buffer but just show the code you use to clear and render each frame. Also, lessqual is the correct value to set the compare function to.   ;  @Waterwalker.Indeed, I'm talking out of my ass (not enough coffee today). But it's true that you can't clear fp render targets to a value higher than 1.0f in DX9, which for me is random stupidity.   ;Quote:Original post by harveypekar@Waterwalker.Indeed, I'm talking out of my ass (not enough coffee today). But it's true that you can't clear fp render targets to a value higher than 1.0f in DX9, which for me is random stupidity.Shouldn't everything beyond 1.0 after projection be clipped away anyways?@kanato: Have you actually cleared the z-buffer before drawing? If your depth test is less-than [or equal], clear it to 1.0, if it is greater-than [or equal], clear it to 0.0. See also msdn:Quote:IDirect3DDevice9::Clear()HRESULT Clear(  DWORD Count,  CONST D3DRECT * pRects,  DWORD Flags,  D3DCOLOR Color,  float Z,  DWORD Stencil);Haven't done DirectX for some 4-5 years, but the following should work for you:device->Clear (  0, NULL,  D3DCLEAR_ZBUFFER, // optionally bitor it with D3DCLEAR_TARGET to clear colors  0,// Would go ((alpha<<24) | (red<<16) | (green<<8) | blue),// with each argb [0..255], only needed when D3DCLEAR_TARGET    // enabled.  1.0f,  // depth  0);;Quote:Original post by harveypekar@Waterwalker.Indeed, I'm talking out of my ass (not enough coffee today). But it's true that you can't clear fp render targets to a value higher than 1.0f in DX9, which for me is random stupidity.Well, even if it could be possible to clear your depth target with values greater than 1.0 it wouldn't make much sense. All depth related stuff works with values projected into the [0,1] range hence clear values outside this range wouldn't make much sense. Sure you can come up with the need to store other depth values in floating point textures used as depth buffer. But this would either require a z write in your pixel shader (almost never a good idea) or a non-standard projection matrix messing around with the projected depth values.However, to clear your depth buffer with other values you can easily write your own pixel shader with Z output ;)   ;Quote:Original post by Waterwalker@harveypekarDefine "random stupidity" for me, pleaase.@OPWhat is your value for zfar? What is the placement and position of your objects you are trying to render? 1.0f is the correct value to clear the depth buffer but just show the code you use to clear and render each frame. Also, lessqual is the correct value to set the compare function to.I've tried greaterequal as well but same results.  zfar is 100.  I'm rendering a cube and some flat squares.  Objects are being rendered at a distance of about 15.  This is easy to tell, since if I set zfar to about 15 then I see the objects clipped by the far clipping plane when the z buffer is turned off.My code has plugable back-ends, and the exact same matrices work with the OpenGL backend with z-buffering enabled.  So I'm quite certain that the projection matrices are good.Quote:Original post by phresnelShouldn't everything beyond 1.0 after projection be clipped away anyways?Yes, anything beyond z = 1.0 after transformation is clipped.  I can see this working with the z-buffer disabled.Quote:Original post by phresnel@kanato: Have you actually cleared the z-buffer before drawing? If your depth test is less-than [or equal], clear it to 1.0, if it is greater-than [or equal], clear it to 0.0.I've tried each of the following blocks to clear the z-buffer, and all of them give the same results.  I have set a break point on these lines and it breaks on them, so I know this code is getting executed.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, color.ToArgb(), 1.0f, 0);device.Clear(ClearFlags.Target, color.ToArgb(), 0, 0);device.Clear(ClearFlags.ZBuffer, 0, 1.0f, 0);System.Drawing.Rectangle[] rect = new System.Drawing.Rectangle[1];rect[0] = new System.Drawing.Rectangle(0, 0, 800, 600);device.Clear(ClearFlags.ZBuffer, color.ToArgb(), 1.0f, 0, rect);Here's something weird.  I'm using a Microsoft.DirectX.Direct3D.Line object to draw some lines.  I assume this object just wraps the ID3DXLine object. This object doesn't respect the clipping planes at all, if lines are drawn behind the camera they still show up on screen.  But with the z-buffer enabled, nothing shows up.  (I have tried disabling this code to see if D3DX is setting some state behind my back that is interfering -- no luck.  I still get nothing drawn when the z-buffer is enabled even when the only thing drawn is from my vertex buffer.);  Ok, I solved it.  It turned out to be really dumb.  It turns out to have been caused by the linespresent.BackBufferWidth = 1;present.BackBufferHeight = 1;in the initialization of my device.  I think that code was there originally to avoid having zeroes for the back buffer size.  What's funny is that it worked when no z-buffer was created.   