DirectX SDK

Step 4.2: Create the Surfaces

[Visual Basic]

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

[C++]

After the DDSURFACEDESC2 structure is filled, you can use it and lpDD, the pointer to the DirectDraw object that was created by the DirectDrawCreateEx function, to call the IDirectDraw7::CreateSurface method, as shown in the following example:

ddrval = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL); 
if(ddrval == DD_OK) 
{ 
    // lpDDSPrimary points to the new surface. 
} 
else 
{ 
    // The surface was not created. 
    return FALSE; 
} 
 

The lpDDSPrimary parameter will point to the primary surface returned by CreateSurface if the call succeeds.

After the pointer to the primary surface is available, you can use the IDirectDrawSurface7::GetAttachedSurface method to retrieve a pointer to the back buffer, as shown in the following example:

ddscaps.dwCaps = DDSCAPS_BACKBUFFER; 
ddrval = lpDDSPrimary->GetAttachedSurface(&ddcaps, &lpDDSBack); 
if(ddrval == DD_OK) 
{ 
    // lpDDSBack points to the back buffer. 
} 
else 
{ 
    return FALSE; 
} 
 

By supplying the address of the surface's primary surface and by setting the capabilities value with the DDSCAPS_BACKBUFFER flag, the lpDDSBack parameter will point to the back buffer if the IDirectDrawSurface7::GetAttachedSurface call succeeds.

Next: Step 5: Render to the Surfaces