Platform SDK: DirectX

D3DXLoadTextureFromFile

The D3DXLoadTextureFromFile function loads a texture from a file into a mipmap level, performing the necessary color conversion and re-scaling.

HRESULT D3DXLoadTextureFromFile(
  LPDIRECT3DDEVICE7 pd3dDevice,
  LPDIRECTDRAWSURFACE7 pTexture,
  DWORD mipMapLevel,
  LPSTR pSrcName,
  RECT* pSrcRect,
  RECT* pDestRect,
  D3DX_FILTERTYPE filterType
);

Parameters

pd3dDevice
A pointer to the Direct3D device, an IDirect3DDevice7 interface, associated with the texture.
pTexture
A pointer to the DirectDrawSurface that was created with either the D3DXCreateTextureFromFile or D3DXCreateTexture functions. This parameter points to the texture surface object.
mipMapLevel
Indicates mipmap level. See remarks.
pSrcName
A pointer to the file name string. The following file types are supported: BMP, DIB, and DDS; for more information, see remarks.
pSrcRect
A pointer to a RECT structure, identifying the source rectangle. If NULL is specified for this parameter, the whole surface is used.
pDestRect
A pointer to a RECT structure, identifying the destination rectangle. If NULL is specified for this parameter, the whole surface is used.
filterType
A member of the D3DX_FILTERTYPE enumerated type, indicating the filter used for mipmap generation.

Return Values

If the function succeeds, the return value is S_OK.

If the function fails, the return value may be NULL or one of the following values:

D3DERR_TEXTURE_NO_SUPPORT
D3DXERR_D3DXNOTSTARTEDYET
D3DXERR_INVALIDFILEFORMAT
D3DXERR_INVALIDPARAMETER
D3DXERR_NOMATCHFOUND
D3DXERR_NOMEMORY
D3DXERR_NULLPOINTER
D3DXERR_UNSUPPORTEDFILEFORMAT
DDERR_DCALREADYCREATED
DDERR_GENERIC
DDERR_INCOMPATIBLEPRIMARY
DDERR_INVALIDCAPS
DDERR_INVALIDOBJECT
DDERR_INVALIDPARAMS
DDERR_INVALIDPIXELFORMAT
DDERR_INVALIDRECT
DDERR_INVALIDSURFACETYPE
DDERR_NOALPHAHW
DDERR_NOCOOPERATIVELEVELSET
DDERR_NODIRECTDRAWHW
DDERR_NOEMULATION
DDERR_NOEXCLUSIVEMODE
DDERR_NOFLIPHW
DDERR_NOMIPMAPHW
DDERR_NOOVERLAYHW
DDERR_NOTFOUND
DDERR_NOTLOCKED
DDERR_NOZBUFFERHW
DDERR_OUTOFMEMORY
DDERR_OUTOFVIDEOMEMORY
DDERR_PRIMARYSURFACEALREADYEXISTS
DDERR_SURFACEBUSY
DDERR_SURFACELOST
DDERR_UNSUPPORTED
DDERR_UNSUPPORTEDMODE
DDERR_WASSTILLDRAWING

Remarks

This function provides a mechanism to copy pixels from a file to a surface.

Concerning the mipMapLevel parameter:

In the pSrcName parameter, TGA is supported for the following cases: 16-, 24-, and 32-bpp direct color and 8-bpp palettized. Also, 8- and 16-bpp gray scale is supported. RLE versions of the preceding TGA formats are also supported. Note that colorkeying and premultiplied alpha are not currently supported for TGA files.

If the destination surface was created by Direct3DX, then the RECT structure should be specified in the original coordinates of that surface.

This function supports a full range of color-conversion for all surface formats that can be described by a D3DX_SURFACEFORMAT structure. It also implements filtered re-scaling and updates mipmaps automatically.

By taking pDestRect in the space of the original image, the application does not have to worry about how the surface may have been resized as part of the D3DXCreateTexture routine. For example, if an image was 100x150 pixels, then it may end up being 128x256 or 256x256 on different configurations. In both cases, the RECT structure to use to update the upper left quadrant is (0, 0, 50, 75); as if no resizing had taken place.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Version: Requires DirectX 7.0.
  Header: Declared in d3dxcore.h.
  Library: Use d3dx.lib.

See Also

D3DXCreateTextureFromFile, D3DXLoadTextureFromMemory, D3DXLoadTextureFromSurface