Tiling and Decals

Texture coordinates are theoretically defined in the range 0..1 in both directions, but can be easily extended beyond that. This is very useful for tiling materials, like a brick wall. A quad textured in the u,v range from (0,0) to (10,10) will repeat the same texturing pattern 10 times in each direction. Tiling is supported internally in both OpenGL and DirectX. All you have to do is set the proper texture parameters at load time. Under OpenGL, you need the calls:

 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); 

which repeat in both directions. Under DirectX, the same result is achieved by using:

 IDirect3DDevice9::SetSamplerState(0, D3DSAMP_ADDRESSU,  D3DTADDRESS_WRAP); IDirect3DDevice9::SetSamplerState(0, D3DSAMP_ADDRESSU,  D3DTADDRESS_WRAP); 

The syntax for OpenGL and DirectX is very similar.

Decals are the exact opposite. Textures do not repeat and are usually employed on top of another tiling material. The classic example is a car with a sticker. The car's texture can be tiling (some kind of metallic material), whereas the sticker will usually be laid out on top of it and be a decal. Under DirectX, we would need to change the last parameter of the SetSamplerState call to D3DTADDRESS_CLAMP, whereas OpenGL programmers need to change it for GL_CLAMP.



Core Techniques and Algorithms in Game Programming2003
Core Techniques and Algorithms in Game Programming2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 261

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