SAMPLE: Alpha Blending in the Direct3D HAL and HEL

Last reviewed: September 5, 1997
Article ID: Q169626
The information in this article applies to:
  • Microsoft DirectX 3 Software Development Kit, version 3.0

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 (size: 94729 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : 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.

Keywords          : GdiDirect3D
Technology        : kbDirectXSDK
Version           : 3.0
Platform          : WINDOWS
Solution Type     : kbfile kbsample


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 5, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.