?/TD>
Microsoft DirectX 9.0

DXTex Tool


Description

The Microsoft?DirectX?Texture (DXTex) tool enables DirectX software development kit (SDK) users 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 IDirect3DTexture9 interface. Advanced developers will probably want to write their own tools that meet their specific needs, but the DXTex tool provides useful basic functionality.

Functionality

Note that DXTex does not currently support textures with surface formats that do not contain at least an R, G, and B texture (such as D3DFMT_G16R16 and D3DFMT_A8), although Direct3D extensions (D3DX) can load and save such textures in DDS format.

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 one 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 choose to 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. You can also switch by clicking 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 different 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 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.

Keep in mind the following when using the DXTex interface.

Performance

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

DDS File Format

See DDS File Reference for more detailed information about 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 two. To do this, go to the Format menu and click Generate Mip Maps. 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 you import a .bmp file, if there is a file of the same size with a name that ends in "_a" - for example, Sample.bmp and Sample_a.bmp - the second file is loaded as an alpha channel. The blue channel of the second .bmp is stored in the alpha channel. When a document is open, you can explicitly load a .bmp file as the alpha channel by clicking Open As Alpha Channel on the File menu.

To view the alpha channel directly, without the RGB channels, on the View menu, click Alpha Channel Only. 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 Change Background Color on 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. 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, so some DXTex 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 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 application 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. 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 will 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.


© 2002 Microsoft Corporation. All rights reserved.