Graphics Reference
In-Depth Information
BOOL
CGrfxWindowD3D::
OnInitDialog
() {
.
Source file.
GrfxWindowD3D.cpp
file
in
Initialize the D3D graphics system
if
( !GraphicsSystemD3D::GetSystem().CreateGraphicsContext(m
_
hWnd) )
return
FALSE;
the
GrfxWindow
folders
of
D3D
_
GraphicsSystem
the
project.
.
void
CGrfxWindowD3D::
OnPaint
() {
.
GraphicsSystemD3D& theAPI = GraphicsSystemD3D::GetSystem();
if
( theAPI.BeginDraw(width, height) ) {
m
_
LargeSquare.Draw();
m
_
SmallCircle.Draw();
theAPI.EndDrawAndShow();
}
.
Listing 4.8.
D3D
OnCreate()
and
OnPaint()
(Tutorial 4.1).
these two tutorials, we notice a new class defined. Listing 4.7 is the D3D im-
plementation of the
GraphicsSystem
class (from Listing 4.5).
At Label A,
m
_
TheAPI
is declared as
static
, or a class variable. We take advantage of the
class variable construct in object-oriented programming to enforce the singleton
nature of the interface to the graphics API. At Label B, we see two new functions.
•
ShutDown()
. To release relevant memory at deletion time.
•
GetActiveDevice()
. To return the currently active graphics device. This
function conveys the point that each graphics API can support multiple RCs
(or drawing areas).
Figure 4.4.
Tutorial 4.1.
In the interests of saving space and avoiding repetition, the implementation of
the
GraphicsSystemD3D
methods are not shown here. These functions are ba-
sically copies of corresponding portions of code we saw in Listings 3.3 and 4.3.
Listing 4.8 shows that the implementation of the
OnCreate()
and
OnPaint()
functions are almost identical to our prediction from Listing 4.6. With the new
GraphicsSystemD3D
class, the drawing routine of the
CRectangle 2D
class must
be updated (from Tutorial 3.3, Listing 3.6). Listing 4.9 shows that with the
GraphicsSystemD3D
class, the
CRectangle2D
(and
CCircle2D
) classes can ac-
cess the currently active graphics device directly for drawing.
Search WWH ::
Custom Search