Graphics Reference
In-Depth Information
int CGrfxWindowD3D::OnCreate(LPCREATESTRUCT lpCreateStruct) {
(A). Initialize graphics hardware context (GHC).
// Verify D3D SDK is installed.Conceptually, m _ pD3D is the reference to the GHC.
if (NULL == m _ pD3D) m _ pD3D = Direct3DCreate9( D3D _ SDK _ VERSION);
if (NULL == m _ pD3D) return FALSE;
// Inquire the capabilities of graphics adapter. Results are stored in display _ mode
D3DDISPLAYMODE display _ mode;
m _ pD3D->GetAdapterDisplayMode( D3DADAPTER _ DEFAULT, &display _ mode );
(B). Create rendering context (RC).
// present _ params specifies hardware buffer mode for the RC we are about to create.
D3DPRESENT _ PARAMETERS present _ params;
Source file.
GrfxWindowD3D.cpp file in
the GrfxWindow folders of the
D3D _ Rectangles2D project.
.
present _ params.BackBufferFormat = display _ mode.Format;
.
// Creating the RC. m _ pD3DDevice is the reference to the RC.
if ( FAILED(m _ pD3D->CreateDevice( ..., m _ hWnd , ... &m _ pD3DDevice )))
.
Listing 4.3. CGrfxWindowD3D::OnCreate() (Tutorial 3.1).
We are finally ready to examine all of the graphics API calls encountered in Tu-
torial 3.1. Recall that in Tutorial 3.1, we introduced the CGrfxWndD3D class to
CGrfxWndD3D . Recall that this
class is a subclass of the CWnd
class, the generic MFC win-
dow class.
represent the GUI drawing area. We examined drawing with a graphics API in
the OnPaint() function. Here we want to examine the initialization of a graph-
ics API. OnCreate() is called during MFC's window creation time. It is in this
function that we create and initialize the D3D graphics device. Listing 4.3 shows
the structure of the CGrfxWndD3D::OnCreate() function.
(A). Initialize graphics hardware context (GHC). This operation en-
sures that there is a valid Direct3D development environment (or the SDK ).
Conceptually, the results stored in m _ pD3D are a reference to the hardware
graphics adapter (or the GHC). The GetAdapterDisplayMode() function
returns the capabilities of the graphics hardware in display _ mode .
(B). Create rendering context (RC). We s e t t h e present _ params vari-
able with appropriate hardware render buffer specifications and call Create
Device() to create the RC and the corresponding render buffer. The results
are stored in m _ pD3DDevice .The m _ hWnd is the reference to the GUI draw-
Search WWH ::




Custom Search