Texture-Addressing Modes

[Previous] [Next]

Earlier in the chapter, we discussed how to assign texture coordinates to the vertices of primitives. As you learned, the u and v texture coordinates assigned to a vertex usually range from 0.0 to 1.0. DirectX allows you to use values outside this range to create special texturing effects. You can define how Direct3D handles texture coordinates outside this range by setting the texture-addressing mode, which as you saw earlier in the book allows you to create texturing effects such as tiling, wrapping, and mirroring. Tiling a texture across the surface of a primitive is one of the most common uses of texture-addressing modes. The following sections describe the four texture-addressing modes Direct 3D provides: border color, clamp, mirror, and wrap.

Border Color Texture-Addressing Mode

The border color texture-addressing mode is specified by the D3DTADDRESS_BORDER member of the D3DTEXTUREADDRESS enumerated type. This texture-addressing mode causes Direct3D to use the border color for texture coordinates outside the range 0.0 through 1.0.

To set the border color, call IDirect3DDevice7::SetTextureStageState and pass the texture stage identifier as the first argument, the D3DTSS_BORDERCOLOR stage state value as the second argument, and the desired RGBA border color as the third argument. Figure 8-2 illustrates a texture with a border applied.

click to view at full size.

Figure 8-2 Border color texture-addressing mode

Clamp Texture-Addressing Mode

The clamp texture-addressing mode is specified by the D3DTADDRESS_CLAMP member of the D3DTEXTUREADDRESS enumerated type. This texture-addressing mode causes Direct3D to clamp the texture coordinates to the range 0.0 through 1.0. Direct 3D applies the texture once and then smears the color of the pixels at the edge of the texture in the remaining directions. Even if you set the texture coordinates to (0.0, 0.0), (0.0, 4.0), (4.0, 4.0), and (4.0, 0.0), as in the previous examples, Direct 3D will apply the texture only once. The pixel colors at the top of the columns and the ends of the rows are then extended all the way to the top and right side of the primitive's surface, respectively. This line of code sample shows how to clamp a texture:

 pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESS,                                   D3DTADDRESS_CLAMP ); 

Figure 8-3 illustrates how this clamped texture will appear once it's applied to a square surface.

Figure 8-3 Clamp texture-addressing mode

Mirror Texture-Addressing Mode

The mirror texture-addressing mode is specified using the D3DTADDRESS_MIRROR member of the D3DTEXTUREADDRESS enumerated type. This texture-addressing mode mirrors a texture at each integer junction. For example, the texture coordinates (0.0, 0.0), (0.0, 4.0), (4.0, 4.0), and (4.0, 0.0) will apply the texture four times in both the u and v directions. Each row or column that the texture is applied to is a mirror image of the previous row or column. The command used for the mirror texture-addressing mode follows. Figure 8-4 illustrates a texture that's been applied to a square surface using the mirror texture-addressing mode.

 pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESS,                                   D3DTADDRESS_MIRROR ); 

click to view at full size.

Figure 8-4 Mirror texture-addressing mode

Wrap Texture-Addressing Mode

The wrap texture-addressing mode, the default wrapping mode, is specified using the D3DTADDRESS_WRAP member of the D3DTEXTUREADDRESS enumerated type. This texture-addressing mode causes a texture to repeat at each integer junction. For example, if the texture coordinates (0.0,0.0), (0.0,4.0), (4.0,4.0), and (4.0,0.0) were used, Direct3D would apply the texture to the primitive's surface four times in both the u and v directions. The command for using this texture-addressing mode follows, and Figure 8-5 shows how a texture looks once it's applied to a square surface using the wrap texture-addressing mode.

 pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESS,                                   D3DTADDRESS_WRAP ); 

click to view at full size.

Figure 8-5 Wrap texture-addressing mode



Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net