DirectX SDK |
The information in this section pertains only to applications written in C and C++. See Direct3D Immediate Mode Visual Basic Tutorials.
Enumerating texture formats gives your application the power to select a supported texture format for the rendering device. The IDirect3DDevice7::EnumTextureFormats method is used to query the current driver for a list of supported texture formats:
pd3dDevice->EnumTextureFormats( TextureSearchCallback, &ddsd.ddpfPixelFormat );
In the preceding function call, the TextureSearchCallback parameter is the address of the application-defined D3DEnumPixelFormatsCallback callback function that will be called for each texture format in the enumeration process.
In the following code excerpt, taken from the TextureSearchCallback callback function, the loop is looking for a device-supported texture pixel format. Specifically, the code searches for a 16-bit texture. Note that all other formats, such as alpha textures, are ignored:
if( pddpf->dwFlags & (DDPF_LUMINANCE|DDPF_BUMPLUMINANCE|DDPF_BUMPDUDV) ) return DDENUMRET_OK; // Skip any FourCC formats if( pddpf->dwFourCC != 0 ) return DDENUMRET_OK; // Skip alpha modes if( pddpf->dwFlags&DDPF_ALPHAPIXELS ) return DDENUMRET_OK; // We only want 16-bit formats, so skip all others if( pddpf->dwRGBBitCount != 16 ) return DDENUMRET_OK; // We found a good match. Copy the current pixel format to our output // parameter memcpy( (DDPIXELFORMAT*)param, pddpf, sizeof(DDPIXELFORMAT) ); // Return with DDENUMRET_CANCEL to end enumeration. return DDENUMRET_CANCEL; }
Now that a texture format supported by the rendering device has been selected from the enumeration of texture formats, TextureEnum, you can create a surface for the texture. This step is detailed in Step 2: Create a Textured Surface.