Palettized Textures

Direct3D devices can support texturing from texture surfaces that use attached palettes. These types of textures are sometimes called "palettized textures." A palettized texture is a DirectDrawSurface object, created with the DDSCAPS_TEXTURE capability, that uses one of the DDPF_PALETTEINDEXEDn pixel formats (where n is 1, 2, 4, or 8). These capabilities are included in the DDSURFACEDESC2 structure that you use to create a texture (and the DDPIXELFORMAT structure that the description contains). Like all palettized surfaces, instead of a color, each pixel is an index into a table of values held within an attached DirectDrawPalette object. For more information about creating and using palettized surfaces, see Surfaces and Palettes in the DirectDraw documentation. As you should always do when checking texture-related device capabilities, be sure to verify the supported texture pixel formats by calling the IDirect3DDevice3::EnumTextureFormats method.

To prepare a palettized texture

  1. Check DirectDraw and Direct3D capabilities as described in this section.
  2. Create a surface of the desired dimensions that includes the DDSCAPS_TEXTURE capability and uses one of the DDPF_PALETTEINDEXEDn pixel formats.
  3. Create and initialize a DirectDrawPalette object. For more information, see Palettes in the DirectDraw documentation. (To use an alpha-only palettized texture, include the DDPCAPS_ALPHA capability when you create the palette. See the reference for IDirectDraw4::CreatePalette for more information.)
  4. Attach the palette to the surface by calling the IDirectDrawSurface4::SetPalette method for the texture surface.

Note  If you create a palettized texture surface, but neglect to attach a palette, your application will cause an access violation within Direct3D Immediate Mode during rendering.

The palettes you use with palettized textures need not be limited to color data. In some cases, devices support texture palettes that also contain alpha information. If so, DirectDraw will expose the DDPCAPS_ALPHA palette capability flag when you call the IDirectDraw4::GetCaps method—the flag is found in the dwPalCaps member of the associated DDCAPS structure. If the rendering device can perform texturing from alpha-capable palettized textures, it will expose the D3DPTEXTURECAPS_ALPHAPALETTE capability when you call IDirect3DDevice3::GetCaps. (The D3DPTEXTURECAPS_ALPHAPALETTE flag can be found in the two D3DPRIMCAPS structures contained by the D3DDEVICEDESC structure you pass with the call.)