Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture Wrapping problem

Started by spythebeast May 20, 2005 at 1:19 PM 3 replies 1.3k views
Original Post
spythebeast
spythebeast
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

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);
}


Any ideas? Thanks [Edited by - Coder on May 20, 2005 2:23:10 PM]
Jiia
Jiia
Quote:

Setting the Addressing Mode
You can set texture addressing modes for individual texture stages by calling the IDirect3DDevice9::SetSamplerState method. Specify the desired texture stage identifier in the first parameter. Set the second parameter to D3DSAMP_ADDRESSU, D3DSAMP_ADDRESSV, or D3DSAMP_ADDRESSW values to update the u-, v-, or w-addressing modes individually. The third parameter you pass to IDirect3DDevice9::SetSamplerState determines which mode is being set. This can be any member of the D3DTEXTUREADDRESS enumerated type. To retrieve the current texture address mode for a texture stage, call IDirect3DDevice9::GetSamplerState, using the D3DSAMP_ADDRESSU, D3DSAMP_ADDRESSV, or D3DSAMP_ADDRESSW members of the D3DSAMPLERSTATETYPE enumeration to identify the address mode about which you want information.
spythebeast
spythebeast
Quote:
Original post by Jiia
Quote:

Setting the Addressing Mode
You can set texture addressing modes for individual texture stages by calling the IDirect3DDevice9::SetSamplerState method. Specify the desired texture stage identifier in the first parameter. Set the second parameter to D3DSAMP_ADDRESSU, D3DSAMP_ADDRESSV, or D3DSAMP_ADDRESSW values to update the u-, v-, or w-addressing modes individually. The third parameter you pass to IDirect3DDevice9::SetSamplerState determines which mode is being set. This can be any member of the D3DTEXTUREADDRESS enumerated type. To retrieve the current texture address mode for a texture stage, call IDirect3DDevice9::GetSamplerState, using the D3DSAMP_ADDRESSU, D3DSAMP_ADDRESSV, or D3DSAMP_ADDRESSW members of the D3DSAMPLERSTATETYPE enumeration to identify the address mode about which you want information.


I have already done this, If you look at the code, I have the lines...

device.SamplerState[0].AddressU = TextureAddress.Wrap;
device.SamplerState[0].AddressV = TextureAddress.Wrap;

This is what is confusing me , several people have had this problem , but it has always been fixed by adding these lines, but not for me it seems..
Jiia
Jiia
Can we see a screenshot, or perhaps you can explain what it looks like? Is the last pixel in the texture stretching through the rest of the surface?
spythebeast
spythebeast
Just solved the problem

I changed
tex = new Texture(device,new Bitmap("tex.jpg",false),0,Pool.Managed);

to

tex = TextureLoader.FromFile(device,"tex.jpg");

I'd love to know why this small change in the texture loading caused such a difference..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.