Platform SDK: DirectX |
Depth buffering is a method of removing hidden lines and surfaces. For a conceptual overview, see What Are Depth Buffers?. By default, Direct3D does not use depth buffering.
C++ applications update the depth buffering state with the D3DRENDERSTATE_ZENABLE render state, using one of the members of the D3DZBUFFERTYPE enumeration to specify the new state value.
If, for some reason, your application needs to prevent Direct3D from writing to the depth buffer, it can use the D3DRENDERSTATE_ZWRITEENABLE enumerated value, specifying FALSE as the second parameter for the call to IDirect3DDevice7::SetRenderState.
The following code fragment shows how the depth buffer state is set to enable z-buffering:
// This code fragment assumes that lpD3DDevice is a valid // pointer to an IDirect3DDevice7 interface. // Enable z-buffering. lpD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_TRUE); // D3DZB_TRUE is the same as TRUE
Your application can also use the D3DRENDERSTATE_ZFUNC render state to control the comparison function that Direct3D uses when performing depth buffering.
Z-biasing is a method of displaying one surface in front of another even if their depth values are the same. You can use this technique for a variety of effects. A common example is rendering shadows on walls. Both the shadow and the wall have the same depth value. However, you want your application to show the shadow on the wall. Giving a z-bias to the shadow makes Direct3D display them properly (see D3DRENDERSTATE_ZBIAS).
You can update the depth buffering state from a Visual Basic application with the D3DRENDERSTATE_ZENABLE render state, using one of the members of the CONST_D3DZBUFFERTYPE enumeration to specify the new state value.
If, for some reason, your application needs to prevent Direct3D from writing to the depth buffer, it can use the D3DRENDERSTATE_ZWRITEENABLE render state, specifying D3DZB_FALSE as the second parameter for the call to Direct3DDevice7.SetRenderState.
The following Visual Basic code fragment shows how the depth buffer state is set to enable z-buffering:
' This code fragment assumes that D3DDevice contains a valid ' reference to a Direct3DDevice7 object. ' Enable z-buffering. Call D3DDevice.SetRenderState(D3DRENDERSTATE_ZENABLE, _ D3DZB_TRUE)
Your application can also use the D3DRENDERSTATE_ZFUNC render state to control the comparison function that Direct3D uses when performing depth buffering.
Z-biasing is a method of displaying one surface in front of another even if their depth values are the same. You can use this technique for a variety of effects. A common example is rendering shadows on walls. Both the shadow and the wall have the same depth value. However, you want your application to show the shadow on the wall. Giving a z-bias to the shadow makes Direct3D display them properly (see D3DRENDERSTATE_ZBIAS).