Platform SDK: DirectX |
This section pertains only to application development in Visual Basic. See Direct3D Immediate Mode C/C++ Tutorials.
Direct3D applications often rely on depth buffers to properly display objects in a scene. For a conceptual overview, see Depth Buffers. To use depth buffering you must enumerate supported depth-buffer formats, create a depth-buffer surface, attach the depth-buffer surface to a render-target surface, and enable depth buffering for the rendering device.
The ZBuffer tutorial application performs the following steps to use a z-buffer:
A z-buffer holds the state for every pixel rendered, indicating what depth the rendered pixel is supposed to represent. In this way, when pixels are rendered on top of each other, the rendered pixel can decide if it should be placed behind the pixel that has already been rendered.
Note The code in the ZBuffer tutorial application is nearly identical to the code in the Triangle tutorial application. This tutorial focuses only on the depth-buffer code unique to ZBuffer, and does not cover setting up Direct3D, rendering, shutting down, or processing events raised by the application. For information on these tasks, see Tutorial 1: Rendering a Single Triangle.
Because some rendering devices require depth buffers to be located in particular places in memory, the system requires that you create and attach the depth-buffer surface to the render-target surface before you create a rendering device.