Game Development Reference
In-Depth Information
Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
7.4 Creating an Alpha Channel
Using the DirectX Texture Tool
The most common image file formats do not store alpha information. In
this section we show you how to create a DDS file with an alpha chan-
nel using the DirectX Texture tool. A DDS file is an image format
specifically designed for DirectX applications and textures. DDS files
can be loaded into textures using D3DXCreateTextureFromFile
just as BMP and JPG files can be. The DirectX Texture tool is located
in the \Bin\DXUtils folder of your root DXSDK directory.
Open the DirectX Texture tool and the crate.jpg file located in this
chapter's sample folder. The crate is automatically loaded in as a 24-bit
RGB texture with 8 bits of red, 8 bits of green, and 8 bits of blue per
pixel. We need to augment this texture to a 32-bit ARGB texture,
reserving an extra 8-bit slot for the alpha channel. Select Format from
the menu and choose Change Surface Format . A dialog box pops up,
as shown in Figure 7.5. Select the A8 R8 G8 B8 format and press OK .
Figure 7.5: Changing the
format of the texture
This creates an image with a 32-bit color depth for each pixel with 8
bits for the alpha channel, 8 bits for red, 8 bits for green, and 8 bits for
blue. Our next task is to load data into the alpha channel. We load the
8-bit grayscale map shown in Figure 7.3 into the alpha channel. Select
File from the menu, and then choose Open Onto Alpha Channel Of
This Texture . A dialog box pops up asking you to locate the image file
that contains the data you want to load into the alpha channel. Select
Search WWH ::




Custom Search