Microsoft DirectX 8.1 (Visual Basic)

DXTex Tool

Description

The DXTex tool enables you to create texture maps that use the new DXTn compression formats. Creating a DXTn-compressed texture is not difficult. However, Microsoft® Direct3D® can do the conversion for you when using the Direct3DTexture8 object. Advanced developers can write tools that meet their specific needs, but the DXTex tool provides useful basic functionality.

Functionality

Path

Source: (SDK root)\Samples\Multimedia\Direct3D\DXTex

Executable: (SDK root)\Bin\DXUtils

User Interface

DxTex uses a fairly traditional user interface (UI) in that each texture map is a document, and several documents can be open at a time. However, each document can hold the texture in either one or two formats simultaneously while the document is open in DxTex. For example, you can import a .bmp file, which automatically creates a 32-bit ARGB texture. You can then convert the texture to DXT1 format. The document now has the image open in both formats, and you can switch between the formats by clicking the window or choosing Original View or New View on the View menu. This makes it easy for you to observe any artifacts introduced by image compression, and to try several compression formats without progressive degradation of the image. For example, if this technique is not used and you convert an image from ARGB to DXT1, all but one bit of alpha is lost.

If you then decide to convert to DXT2, there are still only two alpha levels. Using the DxTex system, the second conversion is done from the original ARGB format, and the DXT2 image contains 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.

Keep in mind the following when using the DxTex interface.

Performance

DxTex uses the Microsoft Direct3D Reference Rasterizer to draw the textures, regardless of what three-dimensional (3-D) hardware is available. So with larger textures (greater than 256-by-256 pixels), the program may be somewhat slow, depending on your CPU speed.

DDS File Format

See DDS File Format for more detailed information on the .dds file format.

Mipmaps

Mipmapping is a technique that improves image quality and reduces texture memory bandwidth by providing prefiltered versions of the texture image at multiple resolutions.

To generate mipmaps in DxTex, the width and height of the source image must both be powers of 2. To do this, click Generate Mip Maps on the Format menu. Filtering is done through a simple box filter. That is, the four nearest pixels are averaged to produce each destination pixel.

Alpha

Many texture formats include an alpha channel, which provides opacity information at each pixel. DxTex fully supports alpha in textures. When importing a .bmp file, if there are two files of the same size and one of the file names ends in "_a" (for example, Sample.bmp and Sample_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, you can explicitly load a .bmp file as the alpha channel by, on the File menu, clicking Open As Alpha Channel.

To view the alpha channel directly without the RGB channels, click Alpha Channel Only on the View menu. The alpha channel appears as a grayscale image. If no alpha channel has been loaded, every pixel has a full alpha channel and the image appears solid white when viewing "Alpha Channel Only". To turn off alpha channel viewing, click the Alpha Channel Only command a second time.

In the usual view, the effect of the alpha channel is visible because the window has a solid background color that shows through the texture where the alpha channel is less than 100 percent. You can change this background color by clicking the View menu, and then clicking Change Background Color. 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. This means that the red, green, and blue values stored in the surface are already multiplied by the corresponding alpha value. Direct3D cannot copy from a surface that contains premultiplied alpha to one that contains non-premultiplied alpha. Therefore, some DxTex operations—such as 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 that do not support DXTn textures. This is because Direct3D cannot copy them to a traditional ARGB surface either, unless that ARGB surface uses premultiplied alpha as well, which is rare. For this reason, you might find it easier to use DXT3 rather than DXT2, and DXT5 rather than DXT4 when possible.

Command Line Options

You can use command-line options to pass input files, an output file name, and processing options to DxTex. 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:               Name of the file to load. This can be a .bmp 
                          or .dds file.

-a alphaname:             The next parameter is the name of a .bmp 
                          file to load as the alpha channel. If no 
                          alpha filename is specified, DxTex still 
                          looks for a file named Infilename_a.bmp and, 
                          if it exists, use that file as the alpha 
                          channel.

-m:                       Mipmaps are generated.

DXT1|DXT2|DXT3|DXT4|DXT5: Compression format. If no format is 
                          specified, the image is be in ARGB-8888.

outfilename:              Name of the destination file. If this option 
                          is not specified, the user interface shows 
                          the current file and all requested 
                          operations. If an outfilename is specified, 
                          the application exits after saving the 
                          processed file without presenting a user 
                          interface.