Original Post
I'm trying to wrap a texture accross a heightmap (I'm using managed directx 9) I have made the texel co-ordinates range between 0,0 and 3,3 , in order to wrap the texture across the heightmap 3 times. However it only displays the texture once, but it displays it at about the right size to fit another 3 accross and down... Here is the code Any ideas? Thanks [Edited by - Coder on May 20, 2005 2:23:10 PM]
float uIncrement = (float)3f / (float)(HEIGHT - 1);
float vIncrement = (float)3f / (float)(WIDTH - 1);
vb = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), WIDTH*HEIGHT, device, Usage.Dynamic | Usage.WriteOnly,
CustomVertex.PositionNormalTextured.Format, Pool.Default);
vertices = new CustomVertex.PositionNormalTextured[WIDTH*HEIGHT];
for (int x=0;x<WIDTH;x++)
{
for (int z=0; z<HEIGHT;z++)
{
float uVal = (float)(z * uIncrement);
float vVal = (float)(x * vIncrement);
Vector3 normalVector = new Vector3(x+0.5f,1,z-0.5f);
vertices[x+z*WIDTH] = new CustomVertex.PositionNormalTextured(new Vector3(x,(heightData[x,z] * heightMultiply),z),normalVector,uVal,vVal);
}
}
public void draw() {
device.SamplerState[0].AddressU = TextureAddress.Wrap;
device.SamplerState[0].AddressV = TextureAddress.Wrap;
device.VertexFormat =CustomVertex.PositionNormalTextured.Format;
device.SetStreamSource(0, vb, 0);
device.Indices = ib;
device.Material = mtrl;
device.SetTexture(0,tex);
device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,WIDTH*HEIGHT,0,indices.Length/3);
}