|Microsoft DirectX 9.0|
Texture resources are implemented in the IDirect3DTexture9 interface. To obtain a pointer to a texture interface, call the IDirect3DDevice9::CreateTexture method or any of the following Direct3D extensions (D3DX) functions.
The following code example uses D3DXCreateTextureFromFile to load a texture from Tiger.bmp.
// The following code example assumes that D3dDevice // is a valid pointer to an IDirect3DDevice9 interface. LPDIRECT3DTEXTURE9 pTexture; D3DXCreateTextureFromFile( d3dDevice, "tiger.bmp", &pTexture);
The first parameter that D3DXCreateTextureFromFile accepts is a pointer to an IDirect3DDevice9 interface. The second parameter tells Microsoft?Direct3D?the name of the file from which to load the texture. The third parameter takes the address of a pointer to an IDirect3DTexture9 interface, representing the created texture object.
Direct3D supports multiple texture blending through the concept of texture stages. Each texture stage contains a texture and operations that can be performed on the texture. The textures in the texture stages form the set of current textures. For more information, see Texture Blending. The state of each texture is encapsulated in its texture stage.
In a C++ application, the state of each texture must be set with the IDirect3DDevice9::SetTextureStageState method. Pass the stage number (0-7) as the value of the first parameter. Set the value of the second parameter to a member of the D3DTEXTURESTAGESTATETYPE enumerated type. The final parameter is the state value for the particular texture state.
Using texture interface pointers, your application can render a blend of up to eight textures. Set the current textures by invoking the IDirect3DDevice9::SetTexture method. Direct3D blends all current textures onto the primitives that it renders.
Your application can set the texture wrapping state for the current textures by calling the IDirect3DDevice9::SetRenderState method. Pass a value from D3DRS_WRAP0 through D3DRS_WRAP7 as the value of the first parameter, and use a combination of the D3DWRAPCOORD_0, D3DWRAPCOORD_1, D3DWRAPCOORD_2, and D3DWRAPCOORD_3 flags to enable wrapping in the u, v, or w directions.
Your application can also set the texture perspective and texture filtering states. See Texture Filtering.