Alpha Blending in the Direct3D HAL and HEL

ID: Q169626


The information in this article applies to:


SUMMARY

The D3DALPHA Direct3D Immediate Mode sample demonstrates how to create a texture based on "alpha pixels," using a source and destination DirectDraw surface.

The example application and source code is in a self-executable compressed file. The following file is available for download from the Microsoft Software Library:

~ D3dalpha.exe
For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q119591 How to Obtain Microsoft Support Files from Online Services


MORE INFORMATION

Alpha blending mixes colors at the pixel level. Alpha values can be specified for a texture on every pixel contained in that texture's surface. Call IDirect3DDevice::EnumTextureFormats() to find out which pixel formats support alpha channels for your device. A wide range of texture pixel formats are supported by the RGB HEL. A few of these formats support alpha channel information. To view a table that shows these formats, go to the DirectX SDK help file and type in "texture map formats" for the index. The D3DALPHA sample demonstrates how to create and use an alpha texture in the HEL and in the HAL. If alpha textures are supported on your 3D hardware, the sample selects and uses the HAL. The RGB HEL is used if 3D hardware is not found.

D3DALPHA shows how to create an alpha texture surface and alpha texture object and fill it with data included in a BMP file. The creation of the alpha texture is done in a two-step process. A source texture surface is created in system memory and a source texture object is created by calling QueryInterface() on that surface. A second, initially empty, DirectDraw texture surface is created in video memory if 3D accelerated hardware was selected. If it is using the HEL, the second surface is created in system memory. A second texture object, the destination texture, is created based on this surface. The source texture is loaded into the destination texture surface with a call to IDirect3DTexture::Load() and then discarded. This process allows a 3D accelerated device to compress a texture map as it enters video memory during the IDirect3DTexture::Load() call. The creation of textures must be done in this manner. For further example code on the creation of source and destination texture objects and texture surfaces, review file "texture.c" in the "misc" directory of the DirectX SDK samples.

When creating the background texture, the sample first tries to find a pixel format that supports 8BPP palettized mode. If it cannot find an 8BPP palettized pixel format, it chooses a 16BPP RGB pixel format. For the alpha texture, the sample tries to find a 16BPP pixel format. If a 16BPP pixel format is not enumerated by EnumTextureFormats(), then a 32BPP format is chosen. If a pixel format with alpha channels is not found, then the application exits with an error.

Additional query words:


Keywords          : kbfile kbsample KbDirectX300 kbSDKWin32 
Version           : WINDOWS:3.0
Platform          : WINDOWS 
Issue type        : kbinfo 

Last Reviewed: June 17, 1999