Graphics Reference
In-Depth Information
scene geometries (e.g., the rectangles).
TheAPI
is the object representing our
interface to the graphics API. Because there should be only one interface to the
graphics API, we define a static singleton variable that is globally accessible. Now
we can examine the actual implementation of the
GraphicsSystem
class.
Tutorial 4.1. The D3D
GraphicsSystem
Class
Tutorial 4.1.
Project Name
D3D
_
GraphicsSystem
•
Goal.
Increase the readability of our source code by hiding low-level graph-
ics API function calls.
•
Approach.
Design an abstraction for a graphics API based on the require-
Tutorial 3.5.
Recall that
in Tutorial 3.5 we worked
with the
CRectangle2D
and
CCircle2D
classes to draw a
scene with a rectangle and a
circle.
ments of our applications. For example, in this tutorial we will implement
the
GraphicsSystem
class of Listing 4.5 based on the D3D graphics API.
We will integrate the new class into the source code of Tutorial 3.5.
Figure 4.4 is a screenshot of running Tutorial 4.1. Not surprisingly, this out-
put is identical to that of Tutorial 3.5. However, if we compare the source code of
class
GraphicsSystemD3D {
A:
// class variable for representation of singleton interface to the D3D API.
public
:
static
GraphicsSystemD3D& GetSystem();
private
:
static
GraphicsSystemD3D m
_
TheAPI;
Source file.
D3DGraphicsSystem.h
file
in the
GraphicsSystem
folders
of the
D3D
_
GraphicsSystem
project.
B:
// public interface for initialization/termination/accessing
public
:
bool
CreateGraphicsContext(HWND hWindow);
void
ShutDown();
LPDIRECT3DDEVICE9
GetActiveDevice();
C:
// public interface initializing the device for drawing
bool
BeginDraw(
float
width,
float
height);
bool
EndDrawAndShow();
D:
// private representation of the D3D interface.
private
:
// This is the D3D Interface (GHC)
LPDIRECT3D9
m
_
pD3D;
// This is one drawing pipeline (RC)
LPDIRECT3DDEVICE9
m
_
pD3DDevice;
};
Listing 4.7.
The D3D
GraphicsSystem
class.
Search WWH ::
Custom Search