Platform SDK: DirectX

Step 1: Create the Off-Screen Surfaces

[Visual Basic]

The information in this section pertains only to applications written in C and C++. See DirectDraw Visual Basic Tutorials.

[C++]

The following code is added to the doInit sample function in DDEx3 to create the two off-screen buffers.

// Create an off-screen bitmap. 
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; 
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; 
ddsd.dwHeight = 480; 
ddsd.dwWidth = 640; 
ddrval = lpDD->CreateSurface(&ddsd, &lpDDSOne, NULL); 
if(ddrval != DD_OK) 
{ 
    return initFail(hwnd); 
} 
 
// Create another off-screen bitmap. 
ddrval = lpDD->CreateSurface(&ddsd, &lpDDSTwo, NULL); 
if(ddrval != DD_OK) 
{ 
    return initFail(hwnd); 
} 
 

The dwFlags member specifies that the application will use the DDSCAPS structure, and it will set the height and width of the buffer. The surface will be an off-screen plain buffer, as indicated by the DDSCAPS_OFFSCREEN flag set in the DDSCAPS structure. The height and the width are set as 480 and 640, respectively, in the DDSURFACEDESC2 structure. The surface is then created by using the IDirectDraw7::CreateSurface method.

Because both of the off-screen plain buffers are the same size, the only requirement for creating the second buffer is to call IDirectDraw7::CreateSurface again with a different pointer name.

You can also specifically request that the off-screen buffer be placed in system memory or display memory by setting either the DDSCAPS_SYSTEMMEMORY or DDSCAPS_VIDEOMEMORY capability in the DDSCAPS structure. By saving the bitmaps in display memory, you can increase the speed of the transfers between the off-screen surfaces and the back buffer. This will become more important when using bitmap animation. However, if you specify DDSCAPS_VIDEOMEMORY for the off-screen buffer and not enough display memory is available to hold the entire bitmap, a DDERR_OUTOFVIDEOMEMORY error value will be returned when you attempt to create the surface.

Next: Step 2: Load the Bitmaps to the Off-Screen Surfaces