Graphics Reference
In-Depth Information
void
CTutorialDlg::OnPaint() {
graphicsDevice
: is the reference to the underlying graphics device.
if
( graphicsDevice.GraphicsDeviceReady() ) {
// Select a and clear graphics device
graphicsDevice.BeginDeviceDraw();
graphicsDevice.DefineCoordinateSystem(applicationWindowDimension);
Source file.
Pseudocode; no
corresponding source file.
largeSquare.Draw(graphicsDevice);
smallSquare.Draw(graphicsDevice);
// Present the drawn result in the application window
graphicsDevice.EndDeviceDraw();
}
}
Listing 3.5.
API-independent rendering procedure.
Based on experience from Tutorial 3.1 and Tutorial 3.2, we can derive an API-
independent rendering process and reimplement the
OnPaint()
function. It is
obvious that to properly support Listing 3.5, we must define/implement the fol-
lowing classes.
•
GraphicsDevice
. This is the abstraction of the
m
_
pD3DDevice
of List-
ing 3.3 and
m
_
hRenderContext
of Listing 3.4. Unfortunately, at this point
we do not understand how these devices were created/initialized. For this
reason, we will defer the implementation of the
GraphicsDevice
class to
the next chapter, after we understand the general principles of working with
graphics APIs. We will derive a proper abstraction for
GraphicsDevice
in
Tutorial 4.1.
•
Rectangle
. This is the class that must support the square geometries of
our scene. Listing 3.6 shows a simple implementation of a D3D rectangle
class. In this case, we choose simple
SetCenter()
and
SetSize()
public
methods for setting the geometric information. Internally, we represent the
rectangle by its center position (
m
_
center
_
x
,
m
_
center
_
y
) and its dimen-
sions (
m
_
width
,
m
_
height
). This representation allows for straightforward
scene specification. However, the drawing routines of D3D require vertex
positions of the rectangle. As we can see, the
CRectangle2D::Draw()
function must compute the vertex positions before issuing the drawing re-
quests to D3D.
In general, classes should be designed to support the semantics of the applica-
tion and hide the requirements of the underlying API. For example, the public
Search WWH ::
Custom Search