Graphics Reference
In-Depth Information
•
Step 2: initialize selected hardware and set the coordinate system pa-
rameters.
The
SetFVF()
and
SetRenderState()
functions initialize
the hardware buffer. The next few lines of code are somewhat mysterious
and may appear to be intimidating. However, with a closer look, we see
scale and translate operations based on the width and height of the appli-
cation window. As we will learn in Chapter 10, these few lines of code
are defining an appropriate 2D cartesian coordinate system on the applica-
tion window. The defined coordinate system has the origin located at the
lower-left corner with
x
-and
y
-axes extending in the rightward and upward
directions, respectively, and the implied units of measurement are in pixels.
The scene.
Collection of all
parameters that affect the ren-
dering results. In this case,
the scene is defined by the two
squares.
•
Step 3: clear drawing buffer and draw two squares.
Notice that the first
step in drawing is to ensure a clean buffer, like a clean piece of paper, with
the
Clear()
command. For the actual drawing commands, we observe
numeric values that corresponds to the measurements from Figure 3.4. In
addition, we observe the following.
- Define hardware format (
DeviceVertexFormat
).
This is the graph-
ics hardware vertex format. This structure is defined in the
CGrfxWnd
D3D.cpp
file, where it has an
(x,y,z) m
_
point
location and an
(r,g,
b) m
_
color
color.
In this tutorial, all colors are set to
(0.4,0.4,
0.4)
, or 40% gray.
- Specify geometric information.
The
v[]
array has four
DeviceVer
texFormat
vertices. The
m
_
point
locations of these four vertices are
filled with the measurements from Figure 3.4.
- Draw geometric information.
The
D3DPT
_
TRIANGLEFAN
parame-
ter of the the
DrawPrimitive()
function tells the graphics device
(
m
_
pD3DDevice
) that the geometric information should be interpreted
and drawn as connecting triangles.
The geometric information is
DrawPrimitive.
Readers are
encouraged
to
learn
more
passed to the graphics device in the
(CONST void
*
)v
parameter. In
this way, the
m
_
pD3DDevice
will draw two connecting triangles into
the hardware buffer representing the large square.
- Repeat for the small square.
The filling of geometric information
and drawing operation are repeated for the small square.
about
the
TRIANGLEFAN
parameter
from
D3D
SDK
manuals.
•
Step 4: present the drawing buffer in the application window.
As men-
tioned, to prevent users from seeing partially drawn geometric shapes, all
drawings are directed into internal hardware buffers. The contents of these
buffers are not visible to the user until the
EndScene()
and
Present()
functions are called. In this way, users of the application will only observe
completed images.
Search WWH ::
Custom Search