Direct3D supplies advanced texture-blending capabilities that allow you to combine up to eight textures on a primitive at once. The IDirect3DDevice7 interface provides texture stages as part of Direct3D's multitexturing capability. Each texture stage contains a texture and operations that can be performed on the texture. Together, the textures associated with these stages form the set of current textures.
You set the current textures by using the IDirect3DDevice7::SetTexture method as just discussed. Until you change the textures, all the current textures will be blended on any of the rendered primitives in a scene.
Each texture state is defined by its texture stage. You need to set the state of each texture by using the IDirect3DDevice7::SetTextureStageState method. The first parameter is passed as the stage number (0 to 7). The second parameter is set to a member of the D3DTEXTURESTAGESTATETYPE enumerated type. The third parameter is passed as the state value for the texture state. Here's the declaration for the IDirect3DDevice7::SetTextureStageState method:
HRESULT IDirect3DDevice7::SetTextureStageState( DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue ); |
Parameter | Description |
---|---|
dwStage | Stage identifier of the texture stage this call will affect; devices can currently have up to eight set textures (valid values are 0 to 7) |
dwState | Texture stage to be set; this parameter can be any member of the D3DTEXTURESTAGESTATETYPE enumerated type setting |
dwValue | State value to be set; the dwState parameter determines the meaning of this value |
Here's the definition of the D3DTEXTURESTAGESTATETYPE enumerated type, which defines texture-stage types:
typedef enum _D3DTEXTURESTAGESTATETYPE { D3DTSS_COLOROP = 1, D3DTSS_COLORARG1 = 2, D3DTSS_COLORARG2 = 3, D3DTSS_ALPHAOP = 4, D3DTSS_ALPHAARG1 = 5, D3DTSS_ALPHAARG2 = 6, D3DTSS_BUMPENVMAT00 = 7, D3DTSS_BUMPENVMAT01 = 8, D3DTSS_BUMPENVMAT10 = 9, D3DTSS_BUMPENVMAT11 = 10, D3DTSS_TEXCOORDINDEX = 11, D3DTSS_ADDRESS = 12, D3DTSS_ADDRESSU = 13, D3DTSS_ADDRESSV = 14, D3DTSS_BORDERCOLOR = 15, D3DTSS_MAGFILTER = 16, D3DTSS_MINFILTER = 17, D3DTSS_MIPFILTER = 18, D3DTSS_MIPMAPLODBIAS = 19, D3DTSS_MAXMIPLEVEL = 20, D3DTSS_MAXANISOTROPY = 21, D3DTSS_BUMPENVLSCALE = 22, D3DTSS_BUMPENVLOFFSET = 23, D3DTSS_TEXTURETRANSFORMFLAGS = 24, D3DTSS_FORCE_DWORD = 0x7fffffff, } D3DTEXTURESTAGESTATETYPE; |
These are the members of the D3DTEXTURESTAGESTATETYPE enumerated type:
Although most texture properties are set using SetTextureStageState, you can set the texture-wrapping state (see the section "Texture Wrapping" near the end of this chapter for more information) for the current textures using the IDirect3DDevice7::SetRenderState method. Pass a value from D3DRENDERSTATE_WRAP0 to D3DRENDERSTATE_WRAP7 for the first parameter, and pass the desired combination of the D3DWRAP_U and D3DWRAP_V flags to enable wrapping in the u or v directions. This code shows how to set the texture-wrapping state:
m_pd3dDevice->SetRenderState(D3DRENDERSTATE_WRAP0, D3DWRAP_U); |