After enumerating the Direct3D device drivers, the InitApp function in Rmmain.cpp calls the Direct3DRMCreate function to create the Retained-Mode API:
LPDIRECT3DRM lpD3DRM;
HRESULT rval;
rval = Direct3DRMCreate(&lpD3DRM);
The sample then uses the Direct3DRM object to create the master reference frame (the "scene") and the camera frame by calling the IDirect3DRM::CreateFrame method. After creating the camera frame, this sample calls the IDirect3DRMFrame::SetPosition method to set its position.
rval = lpD3DRM->CreateFrame(NULL, &myglobs.scene);
rval = lpD3DRM->CreateFrame(myglobs.scene, &myglobs.camera);
// Set the position of the camera frame.
rval = myglobs.camera->SetPosition(myglobs.scene, D3DVAL(0.0),
D3DVAL(0.0), D3DVAL(0.0));
The scene and camera members of the myglobs structure have the same type: LPDIRECT3DRMFRAME. The D3DVAL macro creates a value whose type is D3DVALUE from a supplied floating-point number.
Next, InitApp creates a DirectDraw clipper object by calling the DirectDrawCreateClipper function, and associates the window with the clipper object by calling the IDirectDrawClipper::SetHWnd method. This clipper object is subsequently used to create the Direct3D Windows device. The advantage of using a clipper object to create the device is that in this case DirectDraw does the clipping automatically.
LPDIRECTDRAWCLIPPER lpDDClipper;
HWND win;
rval = DirectDrawCreateClipper(0, &lpDDClipper, NULL);
rval = lpDDClipper->SetHWnd(0, win);
InitApp uses the DirectDraw clipper object and the Direct3D driver retrieved by the EnumDrivers function in a call to the locally defined CreateDevAndView function. CreateDevAndView is discussed in the following section, Creating a Direct3DRM Device and Viewport.
GetClientRect(win, &rc);
if (!CreateDevAndView(lpDDClipper, myglobs.CurrDriver,
rc.right, rc.bottom)) {
return FALSE;
}
// Create the scene to be rendered by calling this sample's BuildScene.
if (!BuildScene(myglobs.dev, myglobs.view, myglobs.scene,
myglobs.camera))
return FALSE;
// Ready to render.
myglobs.bInitialized = TRUE;
// Display the window.
ShowWindow(win, cmdshow);
UpdateWindow(win);
return TRUE;