Partager via


Enabling Depth Buffering

After creating a depth buffer (as described in Creating a Depth Buffer), you enable depth buffering by setting the RenderStateManager.ZBufferEnable property of the Device.RenderState property to true. To enable w-buffering, set the device's render state RenderStateManager.UseWBuffer property to true. These steps are illustrated in the following C# code example.

          [C#]
          

using System;
using Microsoft.DirectX.Direct3D;

    // Declare a rendering device.
    Device device = null;

    // Initialize the device.
    .
    .
    .
    
    // Get the device's render state object.
    RenderStates rs = device.RenderState;
    
    // Enable depth buffering.
    rs.ZBufferEnable = true;
    
    // Render the scene.
    .
    .
    .
    
    // Disable depth buffering
    // (note the different syntax; both forms are acceptable)
    device.RenderState.ZBufferEnable = false;
    
    // Use w-buffering.
    device.RenderState.UseWBuffer = true;

Note: To use w-buffering, an application must set a compliant projection matrix, even if it does not use the Microsoft Direct3D transformation pipeline. For information about providing an appropriate projection matrix, see A W-Friendly Projection Matrix. The projection matrix discussed in What Is the Projection Transformation? is compliant.