Rendering a Single Frame

The DoFrame function renders and shows a single frame. This involves rendering the scene and blitting the result to the client area of the application window on the primary surface.

This function handles lost surfaces by attempting to restore the application's surfaces and then retrying the rendering. It is called by the OnMove function (discussed in Redrawing on Window Movement), the OnSize function (discussed in Redrawing on Window Resizing), and the OnPaint function (discussed in Repainting the Client Area).

static HRESULT

DoFrame(void)

{

HRESULT hRes;

// We keeping trying until we succeed or we fail for a reason

// other than DDERR_SURFACELOST.

while (TRUE)

{

hRes = RenderScene();

if (SUCCEEDED(hRes))

{

hRes = lpddPrimary->lpVtbl->Blt(lpddPrimary, &rDstRect,

lpddDevice, &rSrcRect, DDBLT_WAIT, NULL);

if (SUCCEEDED(hRes)) // If it worked.

return hRes;

}

while (DDERR_SURFACELOST == hRes) // Restore lost surfaces

hRes = RestoreSurfaces();

if (FAILED(hRes)) // handle other failure cases

return hRes;

}

}