Game Development Reference
In-Depth Information
us to shorten some of our lines of code. The device context is accessed via the Dir-
ect3D device object's ImmediateContext property.
Next up, we create our viewport. The ViewPort object specifies the area of the
swap chain buffer that we want to draw onto, as well as the minimum and maximum
depth values. The first two parameters we pass in when we create the Viewport
object are the x and y position of the rectangular area we want to draw in. The third
and fourth parameters are the width and height of that area. As you can see, we
have specified that we want to use the entire window to draw on. The last two para-
meters are the minimum and maximum depth values, which are usually set to 0.0f
and 1.0f respectively. These specify how much of the depth range to draw. Setting
them to 0.0f and 1.0f tells it to drawthe entire depth rangeof the scene. Youcould
set both to 0.0f to draw all objects to the foreground, or set both to 1.0f to draw
everything in the background.
As you can see, next up is code consisting of two lines. The first one sets the View-
port we just created on the rasterizer . Remember that, the rasterizer is one of
the stages in the Direct3D graphics processing pipeline. It clips primitives, prepares
them for the pixel shader (another stage in the pipeline), and also determines how to
call the pixel shaders for them.
The second line of code here sets our RenderTargetView on the output merger
(remember that the output merger is a stage of the graphics pipeline).
We've finally reached the last piece of code in our InitD3D() method. It's another
using block, this time getting a Factory object. It then calls the SetWindowAs-
sociation() method on this object. This method takes two parameters: the first
being the handle of our game window and the second being the window association
flags we want to use. In this case, we are using the WindowAssoci-
ationFlags.IgnoreAltEnter flag. So why are we doing this? The answer is
to prevent DXGI from handling Alt + Enter since it does not work properly with
WinForms. Remember that DXGI is one of the namespaces that we included with a
using statement when we started this project. DXGI is short for DirectX Graphics
Infrastructure. We will handle the Alt + Enter keyboard shortcut ourselves later. It will
toggle the fullscreen mode for our program.
Search WWH ::




Custom Search