Game Development Reference
In-Depth Information
class in
Chapter 1
,
Getting Started
, but it is one of those properties that we haven't
discussed in detail in the topic. You can see it in the downloadable code for this
topic. Remember that the
RenderForm
object is a SlimDX object that represents a
window for us to draw on. The next line saves the size of our game window in the
PixelSize
property. The
WindowRenderTargetProperties
object is basically
how we specify the initial configuration for a
WindowRenderTarget
object when
we create it. The last line in our constructor creates our
WindowRenderTarget
ob-
ject, storing it in our
m_RenderTarget
member variable. The two parameters we
pass in are our
Factory
object and the
WindowRenderTargetProperties
ob-
ject we just created. A
WindowRenderTarget
object is a render target that refers
to the client area of a window. We use the
WindowRenderTarget
object to draw in
a window.
Creating our rectangle
Now that our render target is set up, we are ready to draw stuff, but first we need to
create something to draw! So, we will add a bit more code at the bottom of our con-
structor. First, we need to initialize our three
SolidColorBrush
objects. Add these
three lines of code at the bottom of the constructor:
m_BrushRed = new
SolidColorBrush(m_RenderTarget, new
Color4(1.0f, 1.0f, 0.0f, 0.0f));
m_BrushGreen = new
SolidColorBrush(m_RenderTarget, new
Color4(1.0f, 0.0f, 1.0f, 0.0f));
m_BrushBlue = new
SolidColorBrush(m_RenderTarget, new
Color4(1.0f, 0.0f, 0.0f, 1.0f));
This code is fairly simple. For each brush, we pass in two parameters. The first para-
meter is the render target we will use this brush on. The second parameter is the
color of the brush, which is an
ARGB
(
Alpha Red Green Blue
) value. The first para-
meter we give for the color is
1.0f
. The
f
character on the end indicates that this
number is of the
float
data type. We set alpha to
1.0
because we want the brush
to be completely opaque. A value of
0.0
will make it completely transparent, and a
value of
0.5
will be 50 percent transparent. Next, we have the red, green, and blue