Platform SDK: DirectX

Compress Sample

[Visual Basic]

This topic pertains only to application development in C++. See Direct3D Immediate Mode Visual Basic Samples.

[C++]

Description

The Compress sample shows how to load the DDS file format into a compressed texture surface. DDS textures can be created using DxTex included with the DirectDraw tools in the DirectX SDK.

Path

Source: (SDK root)\Samples\Multimedia\D3dim\Src\Compress

Executable: (SDK root)\Samples\Multimedia\D3dim\Bin\Compress.exe

User's Guide

Press F1 to see available commands, or choose from the menu.

Programming Notes

The file format is called DDS because it encapsulates the information in a DirectDrawSurface. The data can be read directly into a surface of a matching format.

The ReadDDSTexture function demonstrations how a DDS surface is read from a file.

A DDS file has the following format:

DWORD dwMagic (0x20534444, or "DDS ")
DDSURFACEDESC2 ddsd Information about the surface format
BYTE bData1[] Data for the main surface
[BYTE bData2[]] Data for attached surfaces, if any, follows.

This format is easy to read and write, and it supports features such as alpha and multiple MIP levels, as well as DXTn compression. If it uses DXTn compression, it can be one of five compressed types. See Compressed Texture Surfaces.

After the texture is read in, a pixel format must be chosen that is supported by the renderer. In the sample, the supported pixel formats are enumerated and stored in a linked list. After the pixel formats are collected, the list is searched for a best match, using the FindBestPixelFormatMatch function.

Some Direct3D devices, such as the reference rasterizer and some hardware devices, can render compressed textures directly. For renderers that do not directly support this, the compressed surface must be blitted to a noncompressed surface. The BltToUncompressedSurface function shows how this is done.