Platform SDK: DirectX

DirectX Texture Tool

Description

The purpose of this tool is to allow developers to create texture maps that use the new DXTn compression formats. Creating a compressed texture is actually not that difficult to do: the IDirectDrawSurface7::Blt method can do the conversion for you. Advanced developers will probably want to write their own tools that meet their specific needs, but this tool provides the following useful basic functionality:

Path

Source: (SDK root)\Samples\Multimedia\DDraw\Src\DXTex

Executable: (SDK root)\Bin\DxUtils\Dxtex.exe

User's Guide

DirectX Texture Tool uses a multidocument interface. Each texture map is a document, and several documents can be open at a time.

Each open document can hold the texture in either one format or two formats at once. For instance, you could import a BMP file, which would automatically create a 32-bit ARGB texture. You could then choose to convert the texture to DXT1 format. The document now remembers the image in both formats, and the user can flip between the formats by clicking in the window or by choosing Original or New from the View menu. This makes it easy for the user to spot any artifacts introduced by image compression, and to try several different compression formats without progressive degradation of the image

If this technique were not used and the user converted an image from ARGB to DXT1, all but one bit of alpha would be lost. If the user then decided to convert to DXT2, there would still be only two alpha levels. With the system used by Direct Texture Tool, the second conversion is done from the original ARGB format, and the DXT2 image will contain all 16 levels of alpha supported by DXT2. When the image is saved, the original format is discarded, and only the new format is stored.

This system has a few consequences that must be remembered:

To create mipmaps, choose Generate MipMaps from the Format menu. The width and height of the source image must both be powers of 2. Filtering is done by a simple box filter—that is, the four nearest pixels are averaged to produce each destination pixel.

DirectX Texture Tool fully supports alpha in textures. When importing a BMP file, if two files exist and one has an "_a" at the end of the name (for example, tex.bmp and tex_a.bmp), the second file will be loaded as an alpha channel. The blue channel of the second .bmp is stored in the alpha channel.

Once a document is open, the user can explicitly load a .bmp file as the alpha channel by using Open As Alpha Channel on the File menu.

To view the alpha channel directly without the RGB channels, choose Alpha Channel Only from the View menu. The alpha channel will appear as a gray-scale image. Note that if no alpha channel has been loaded, the alpha channel will be 100 percent throughout and the image will appear solid white when Alpha Channel Only is selected.

In the normal view, the effect of the alpha channel is visible because the window has a solid background color which shows through the texture where the alpha channel is less than 100 percent. The user can change this background color by choosing Change Background Color from the View menu. This choice does not affect the texture itself or the data that is written when the file is saved.

The DXT2 and DXT4 formats use premultiplied alpha, which means that the red, green, and blue values stored in the surface are already multiplied by the corresponding alpha value. DirectDraw cannot blit from a surface containing premultiplied alpha to one containing non-premultiplied alpha, so some operations (Open as Alpha Channel, conversion to DXT3, and conversion to DXT5) are not possible on DXT2 and DXT4 formats. Supporting textures using these formats is difficult on Direct3D devices which do not support DXTn textures, because DirectDraw cannot handle blitting them to a traditional ARGB surface either (unless that ARGB surface uses premultiplied alpha as well, which is rare). So you may find it easier to use DXT3 rather than DXT2 and DXT5 rather than DXT4 when possible.

Command-line options can be used to pass input files, an output file name, and processing options to DirectX Texture Tool. If an output file name is specified, the program exits automatically after writing the output file, and no user interface is presented.

dxtex [infilename] [-a alphaname] [-m] [DXT1|DXT2|DXT3|DXT4|DXT5] [outfilename]
infilename
The name of the file to load. This can be a .bmp or .dds file.
-a alphaname
If "-a" is specified, the next parameter is the name of a .bmp file to load as the alpha channel. If no alpha filename is specified, the application will still look for a file named infilename_a.bmp and, if it exists, use that as the alpha channel.
-m
If this option is specified, mipmaps are generated.
DXT1 | DXT2 | DXT3 | DXT4 | DXT5
Specifies compression format. If no format is specified, the image will be in ARGB-8888.
outfilename
Specifies the name of the destination file. If this is not specified, the user interface will show the current file and all requested operations. If an outfilename is specified, the application will exit after saving the processed file without presenting a user interface.

See Also

For more information on the DDS file format, see Compress Sample.