Platform SDK: DirectX

Tutorial 2: Using Transparency

[C++]

This section pertains only to application development in Visual Basic. See DirectDraw C/C++ Tutorials.

[Visual Basic]

This second tutorial expands on the concepts learned in the first tutorial by introducing transparent blitting. Transparent blitting enables you to create the illusion of nonrectangular blits when animating sprites. A sprite image is usually nonrectangular, but blits are always rectangular, so every pixel within the sprite's bounding rectangle becomes part of the data transfer. With transparent blitting, each pixel that is not part of the sprite image is treated as transparent when the blitter is moving the image to its destination, so that it does not overwrite the color in that pixel on the background image.

The artist creating the sprite chooses an arbitrary color or range of colors to be used as the transparency color key. This tutorial uses a source color key on the sprite image to give the illusion of a nonrectangular blit.

The first steps of this tutorial are identical to the first tutorial to the point of creating the primary surface in Step 3: Initialize Variables. Therefore, to avoid redundancy, the first step in this tutorial will be to create the back buffer surface.

To demonstrate transparent blitting, the Tutorial 2 sample included in this SDK performs the following steps: