Game Development Reference
In-Depth Information
• Audio
Drawing the world
Once we have an up-to-date game world, we need to display a view of the world to
the players so that they can receive some kind of feedback for their actions. This is
done during the draw stage, which can either be the cheapest or most expensive
part of the frame, depending on what you want to render.
The Draw() method (sometimes also called the Render() method) is commonly
broken down into three sections: clearing the screen, drawing the world, and
presenting the frame to the monitor for display.
Clearing the screen
During the rendering of each frame, the same render target is reused. Just like any
data, it remains there unless we clear it away before trying to make use of the tex-
ture. Clearing the screen is paramount if you use a depth buffer. If you do not clear
the depth buffer, the old data will be used and can prevent certain visuals from ren-
dering when they should, as the GPU believes that something has already been
drawn in front.
Clearing the render target and depth buffer allows us to reinitialize the data in each
pixel to a clean value, ready for use in the new frame.
To clear both the buffers we need to issue two commands, one for each. This
is the first time we will use the views that we created earlier. Using our
ID3D11DeviceContext , we will call both the ClearRenderTargetView() and
ClearDepthStencilView() methods to clear the buffers. For the first method
you need to pass a color that will be set across the buffer. In most cases setting black
(0, 0, 0, 1 in RGBA) will be enough; however, you may want to set a different color
for debug purposes, which you can do here with a simple float array.
Clearing the depth just needs a single floating point value, in this case 1.0f , which
represents the farthest distance from the camera. Data in the depth buffer is rep-
resented by values between 0 and 1 , with 0 being the closest to the camera.
We also need to tell the command which parts of the depth buffer we want to
Search WWH ::




Custom Search