DirectX SDK

Step 3: Attach the Depth Buffer

[Visual Basic]

The information in this section pertains only to applications written in C and C++. See Direct3D Immediate Mode Visual Basic Tutorials.

[C++]

Once the depth buffer is created, you need to attach it to the surface that will be used as the render target. Do this by calling the IDirectDrawSurface7::AddAttachedSurface method of the render-target surface. The ZBuffer sample performs this with the following code:

    // Attach the z-buffer to the back buffer.
    if( FAILED( hr = g_pddsBackBuffer->AddAttachedSurface( g_pddsZBuffer ) ) )
        return hr;

Once the depth buffer is attached to the render-target surface, the system will automatically use the depth buffer whenever depth buffering is enabled, as discussed in Step 4: Enable Depth Buffering.