Microsoft DirectX 8.1 (Visual Basic) |
Texture resources are implemented in the Direct3DTexture8 class. To obtain a texture object, call the Direct3DDevice8.CreateTexture method or any of the following D3DX functions.
The following code example uses D3DX.CreateTextureFromFile to load a texture from Tiger.bmp.
' ' The following code example assumes that d3dDevice ' is a valid Direct3DDevice8 object and that g_D3DX is a valid ' D3DX8 object. ' Dim Texture As Direct3DTexture8 Set Texture = g_D3DX.CreateTextureFromFile( d3dDevice, App.Path + "\tiger.bmp" )
The first parameter that CreateTextureFromFile accepts is a Direct3DDevice8 object. The second parameter tells Microsoft® Direct3D® the name of the file from which to load the texture. This method returns a texture object, which is assigned to Texture.
Microsoft® 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 Microsoft® Visual Basic®, the state of each texture must be set with the Direct3DDevice8.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 CONST_D3DTEXTURESTAGESTATETYPE enumeration. The final parameter is the state value for the particular texture state.
Applications can render a blend of up to eight textures. Set the current textures by invoking the Direct3DDevice8.SetTexture method. Direct3D blends all current textures onto the primitives that it renders.
Note When the texture is no longer needed, you should set the texture at the appropriate stage to Nothing. If you fail to do this, the memory for the surface may be lost when your application closes.
Your application can set the texture wrapping state for the current textures by calling the Direct3DDevice8.SetRenderState method. Pass a value from D3DRENDERSTATE_WRAP0 through D3DRENDERSTATE_WRAP7 as the value of the first parameter and use a combination of the D3DWRAPCOORD_0, D3DWRAPCOORD_1, D3DWRAPCOORD_2, and D3DWRAPCOORD_3 flags from the CONST_D3D enumeration 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.