Microsoft DirectX 8.1 (C++)

D3DXCreateTextureFromFile

Creates a texture from a file.

HRESULT D3DXCreateTextureFromFile(
  LPDIRECT3DDEVICE8 pDevice,
  LPCTSTR pSrcFile,
  LPDIRECT3DTEXTURE8* ppTexture
);

Parameters

pDevice
[in] Pointer to an IDirect3DDevice8 interface, representing the device to be associated with the texture.
pSrcFile
[in] Pointer to a string that specifies the file from which to create the texture.
ppTexture
[out] Address of a pointer to an IDirect3DTexture8 interface, representing the created texture object.

Return Values

If the function succeeds, the return value is D3D_OK.

If the function fails, the return value can be one of the following values.

D3DERR_NOTAVAILABLE
D3DERR_OUTOFVIDEOMEMORY
D3DERR_INVALIDCALL
D3DXERR_INVALIDDATA
E_OUTOFMEMORY

Remarks

This function supports the following file formats: .bmp, .dds, .dib, .jpg, .png, and .tga.

Mipmapped textures automatically have each level filled with the loaded texture.

When loading images into mipmapped textures, some devices are unable to go to a 1×1 image and this function will fail. If this happens, the images need to be loaded manually.

This function supports both Unicode and ANSI strings.

Note that a resource created with this function will be placed in the memory class denoted by D3DPOOL_MANAGED.

For the best performance when using D3DXCreateTextureFromFile:

  1. Doing image scaling and format conversion at load time can be slow. Store images in the format and resolution they will be used in. If the target hardware requires power-of-two dimensions, create and store images using power-of-two dimensions.
  2. For mipmap image creation at load time, filter using D3DXFILTER_BOX. A box filter is much faster than other filter types such as D3DXFILTER_TRIANGLE.
  3. Consider using DDS file. Because DDS files can be used to represent any Microsoft DirectX® 8.x texture format, they are easy for Direct3DX to read. Also, they can store mipmaps, so any mipmap-generation algorithms can be used to author the images.

Requirements

  Header: Declared in D3dx8tex.h.
  Import Library: Use D3dx8.lib.

See Also

D3DXCreateTextureFromFileEx