DirectX SDK

Step 2.3: Copy to the Render Surface

[Visual Basic]

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

[C++]

In order to copy the bitmap to the texture surface, create a device context (DC) for the bitmap and a DC for the surface.

Note  A DC is a GDI structure that stores, retrieves, and modifies the attributes of graphics objects and specifies graphic modes. The DC for the surface contains information that controls the display of graphics on the rendering device. The graphics objects stored in the DC for the bitmap is the bitmap for copying.

You can retrieve the DC for the bitmap with the following code fragment:

    HDC hdcBitmap = CreateCompatibleDC( NULL );
    if( NULL == hdcBitmap )
    {
        pddsTexture->Release();
        return NULL;
    }
    SelectObject( hdcBitmap, hbm );

The CreateCompatibleDC function is a GDI function that creates a memory DC compatible with the specified device (the application's current screen setting). For more information, see the Platform SDK.

Now, you can retrieve the DC for the surface:

    HDC hdcTexture;
    if( SUCCEEDED( pddsTexture->GetDC( &hdcTexture ) ) )
    {

In the preceding code, the IDirectDrawSurface7::GetDC method returns the DC for the surface.

Complete the process of copying the bitmap image to the surface with the following code:

        BitBlt( hdcTexture, 0, 0, bm.bmWidth, bm.bmHeight, hdcBitmap,
                0, 0, SRCCOPY );
        pddsTexture->ReleaseDC( hdcTexture );
    }
    DeleteDC( hdcBitmap );
 
    // Return the newly created texture
    return pddsTexture;
}

The BitBlt function is a graphics device interface (GDI) function that performs a bit-block transfer of color data from the specified source DC (hdcBitmap) into the destination DC (hdcTexture), for more information see the Platform SDK.

Now that you have created a new surface for your texture, you can use that texture during the rendering of the primitives. This task is illustrated in Step 3: Render a Textured Primitive.