Game Development Reference
In-Depth Information
As you can see, this code is fairly simple. At the top of the method, we have the
same
if
statement we've been using here in previous demos. Remember that this
if
statement prevents this method from doing anything if the program isn't initialized
yet or if it has already been disposed of. This prevents the crashing that could other-
wise occur when the program first starts up or shuts down.
The next line of code clears the screen using whatever color is stored in our
ClearColor
property that is defined by the
GameWindow
base class. Then, we call
the
Draw()
method of the Direct3D device context to draw our geometry. This meth-
od takes two parameters. The first one is the total number of vertices we want to
draw. The second parameter is the index to start at in the vertex buffer. We want to
draw all of our vertices, so we set this to
0
to start with the first vertex.
And lastly, we call the
Present()
method on the swap chain. It takes two paramet-
ers. The first parameter is the sync interval, and the second is the present flags. Both
of these are beyond the scope of this chapter, so we are using
0
for the first para-
meter, and
PresentFlags.None
for the second parameter.
Before we test the code, we'll do one more little thing. We will edit the
ToggleFull-
screen()
method of our
TriangleGameWindow
class so it looks like the next
code snippet. Remember that this function is an override of a method defined by our
GameWindow
base class:
public override void ToggleFullscreen()
{
base.ToggleFullscreen();
m_SwapChain.IsFullScreen =
this.IsFullScreen;
}
The first line toggles the value of our
IsFullScreen
property that was defined by
the
GameWindow
base class. The second line sets the fullscreen state of our swap
chain to the new value in the
IsFullScreen
property. With this bit of code, we can
now toggle fullscreen mode while the program is running. If you press
Alt
+
Enter
,
the program will toggle its fullscreen mode. Remember that we added code to detect