DirectX SDK

Step 3: Blit the Off-Screen Surfaces to the Back Buffer

[Visual Basic]

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

[C++]

The WM_TIMER message contains the code for writing to surfaces and flipping surfaces. In the case of DDEx3, it contains the following code to select the proper off-screen surface and to blit it to the back buffer:

rcRect.left = 0; 
rcRect.top = 0; 
rcRect.right = 640; 
rcRect.bottom = 480; 
if(phase) 
{ 
    pdds = lpDDSTwo; 
    phase = 0; 
} 
else 
{ 
    pdds = lpDDSOne; 
    phase = 1; 
} 
while(1) 
{ 
    ddrval = lpDDSBack->BltFast(0, 0, pdds, &rcRect, FALSE); 
    if(ddrval == DD_OK) 
    { 
        break; 
    } 
} 

The phase variable determines which off-screen surface will be blitted to the back buffer. The IDirectDrawSurface7::BltFast method is then called to blit the selected off-screen surface onto the back buffer, starting at position (0, 0), the upper-left corner. The rcRect parameter points to the RECT structure that defines the upper-left and lower-right corners of the off-screen surface that will be blitted from. The last parameter is set to FALSE (or 0), indicating that no specific transfer flags are used.

Depending on the requirements of your application, you could use either the IDirectDrawSurface7::Blt method or the IDirectDrawSurface7::BltFast method to blit from the off-screen buffer. If you are performing a blit from an off-screen plain buffer that is in display memory, you should use IDirectDrawSurface7::BltFast. Although you will not gain speed on systems that use hardware blitter on their display adapters, the blit will take about 10 percent less time on systems that use hardware emulation to perform the blit. Because of this, you should use IDirectDrawSurface7::BltFast for all display operations that blit from display memory to display memory. If you are blitting from system memory or require special hardware flags, however, you have to use IDirectDrawSurface7::Blt.

After the off-screen surface is loaded in the back buffer, the back buffer and the primary surface are flipped in much the same way as shown in the previous tutorials.