顶点结构声明如下:
struct Vertex { Vertex(){} Vertex( float x, float y, float z, float nx, float ny, float nz, float u, float v) { _x = x; _y = y; _z = z; _nx = nx; _ny = ny; _nz = nz; _u = u; _v = v; } float _x, _y, _z; float _nx, _ny, _nz; float _u, _v; // texture coordinates static const DWORD FVF; };
顶点信息如下:后两位为纹理坐标
v[0] = Vertex(-2.0f, -2.0f ,2.0f,0.0f,0.0f,-1.0f,0.0f,1.0f);// ( 0.0f , 1.0f) v[1] = Vertex(-2.0f, 2.0f ,2.0f,0.0f,0.0f,-1.0f,0.0f,0.0f);// ( 0.0f , 0.0f) v[2] = Vertex( 2.0f, -2.0f ,2.0f,0.0f,0.0f,-1.0f,1.0f,1.0f);// ( 1.0f , 1.0f) v[3] = Vertex( 2.0f, 2.0f ,2.0f,0.0f,0.0f,-1.0f,1.0f,0.0f);// ( 1.0f , 0.0f)
纹理图如下:
运行结果如下,即完全显示。
再将纹理坐标改为
v[0] = Vertex(-2.0f, -2.0f ,1.8f,0.0f,0.0f,-1.0f,0.0f,2.0f); // (0.0f,2.0f) v[1] = Vertex(-2.0f, 2.0f ,1.8f,0.0f,0.0f,-1.0f,0.0f,0.0f); // (0.0f,0.0f) v[2] = Vertex( 2.0f, -2.0f ,1.8f,0.0f,0.0f,-1.0f,2.0f,2.0f); // (2.0f,2.0f) v[3] = Vertex( 2.0f, 2.0f ,1.8f,0.0f,0.0f,-1.0f,2.0f,0.0f); // (2.0f,0.0f)
和
v[0] = Vertex(-2.0f, -2.0f ,1.8f,0.0f,0.0f,-1.0f,0.0f,3.0f); // (0.0f,3.0f) v[1] = Vertex(-2.0f, 2.0f ,1.8f,0.0f,0.0f,-1.0f,0.0f,0.0f); // (0.0f,0.0f) v[2] = Vertex( 2.0f, -2.0f ,1.8f,0.0f,0.0f,-1.0f,3.0f,3.0f); // (3.0f,3.0f) v[3] = Vertex( 2.0f, 2.0f ,1.8f,0.0f,0.0f,-1.0f,3.0f,0.0f); // (3.0f,0.0f)
运行结果分别为:
纹理寻址模式为:重复寻址(wrap address mode) 默认这种模式
Device ->SetSamplerState(0,D3DSAMP_ADDRESSU,D3DPTADDRE*S_WRAP);
Device ->SetSamplerState(0,D3DSAMP_ADDRESSV,D3DPTADDRE*S_WRAP);