Jump to content
  • Advertisement
Sign in to follow this  

Custom Quad Terrain/vertex format Texture wrappin issue

This topic is 2812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there :)

Im currently developing my game engine/editor in XNA 4.0 ,

now ive got a bit of a problem.

ive created a grid of quads to use for a terrain, im using a custom vertex format and a Dynamic vertex buffer . i can successfuly modify terrain heigth using this

ive assigned all the vertices a texture coordinate and the rest.
but im just getting the first quad textured and not the rest.

now i understand that we have a AdressMode that sets to WRAP to wrap a texture but ive try'd this in several places ,in my terrain shader the semantic of AddressU/V is also set to WRAP;
but it just doesent wrap my texture;

now the uv coordinates for every group of vertices that make up a quad is the same..
so i dont see why this doesent work.

Anyway here the code im using for my quadterrain assuming this is fine it should work seeying in XNA 4.0 Wrappin is set as default ?

i just dont get why its not wrapping :(

anyway thanks a bunch guys :)

,Chris F.

public class Quad

public MeshBuilder builder;

public TerrainObject.CustomVertex1[] Vertices;
public int[] Indexes;
Vector3 Origin;
Vector3 Normal;
Vector3 Up;
Vector3 Left;

public List<BoundingBox> boxesList;

Vector3 UpperLeft;
Vector3 UpperRight;
Vector3 LowerLeft;
Vector3 LowerRight;
int terrainWidth;
int terrainHeight;

HeightMapInfo heightMapInfo;

public Quad(Vector3 origin, Vector3 normal, Vector3 up,
float width, float height,int terrainwidth , int terrainheight)
Vertices = new TerrainObject.CustomVertex1[terrainwidth * terrainheight];

Origin = origin;
Normal = normal;
Up = up;
terrainWidth = terrainwidth;
terrainHeight = terrainheight;
// Calculate the quad corners
Left = Vector3.Cross(normal, Up);
Vector3 uppercenter = (Up * terrainheight / 2) + origin;
UpperLeft = uppercenter + (Left * terrainwidth / 2);
UpperRight = uppercenter - (Left * terrainwidth / 2);
LowerLeft = UpperLeft - (Up * terrainheight);
LowerRight = UpperRight - (Up * terrainheight);



private void FillVertices()
// Fill in texture coordinates to display full texture
// on quad
Vector2 textureUpperLeft = new Vector2(1.0f,1.0f);
Vector2 textureUpperRight = new Vector2(2.01f, 1.0f);
Vector2 textureLowerLeft = new Vector2(1.0f, 2.01f);
Vector2 textureLowerRight = new Vector2(2.0f, 2.01f);

// Provide a normal for each vertex
for (int i = 0; i < Vertices.Length; i++)
Vertices.Normal = Normal;

for (int x = 0; x < terrainWidth; x++)
for (int y = 0; y < terrainHeight; y++)

Vertices[x + y * terrainWidth].Position = new Vector3(x, (heightMapInfo.heights[x, y] - 1 ) * bumpiness, -y);


Indexes = new int[(terrainWidth - 1) * (terrainHeight - 1) * 6];
int counter = 0;
for (int y = 0; y < terrainHeight - 1; y++)
for (int x = 0; x < terrainWidth - 1; x++)
int lowerLeft = x + y * terrainWidth;
int lowerRight = (x + 1) + y *terrainWidth;
int topLeft = x + (y + 1) * terrainWidth;
int topRight = (x + 1) + (y + 1) * terrainWidth;

Vertices[x + y * terrainWidth].TextureCoordinate = textureLowerLeft;

Vertices[x + (y + 1) * terrainWidth].TextureCoordinate = textureUpperLeft;

Vertices[(x + 1) + y * terrainWidth].TextureCoordinate = textureLowerRight;

Vertices[(x + 1) + (y + 1) * terrainWidth].TextureCoordinate = textureUpperRight;

Indexes[counter++] = topLeft;
Indexes[counter++] = lowerRight;
Indexes[counter++] = lowerLeft;

Indexes[counter++] = topLeft;
Indexes[counter++] = topRight;
Indexes[counter++] = lowerRight;






Share this post

Link to post
Share on other sites
new Vector2(2.01f, 1.0f);

That will get mapped to ( 0.01f, 0 ). For the u coordinate that's just one-hundredth of the texture width.

Try using tex coords like ( 0,0 ), ( 0,1 ), ( 1,0 ), and (1,1).

Share this post

Link to post
Share on other sites
hi Buckeye ,
thanks alot for your quick reply .

the thing is i actually had that set before like that just i changed it to see if it would make a difference , but it gave me the exact same results .

So now ive changed it back to

Vector2 textureUpperLeft = new Vector2(0, 0);
Vector2 textureUpperRight = new Vector2(1, 0);
Vector2 textureLowerLeft = new Vector2(0, 1);
Vector2 textureLowerRight = new Vector2(1, 1);

but its still exacly the same . no change whatsoever.

i really dont get it :S

its just not wrapping for some reason :S

now in XNA 4.0 wrapping is on by default. taking these texture coordinates and the way ive set up the vertices this should b working right ?

even so ive checked all the sampler states and there all set to Wrap .

somthing so trivial is giving me so much trouble its insane.

somthing else i might be overlooking ? anyway thanx again

here picture of my issue , would think u understand what i mean anyway but yh

Image and video hosting by TinyPic

, Chris F.

[Edited by - Chrislilc on October 10, 2010 12:41:25 PM]

Share this post

Link to post
Share on other sites
ive gone over to triangles instead of quads its working fine now ..
i thought that triangles where waste of space cause of redifining vertices but it turns out it reuses vertices to if used as triangle strip ??? lol

im still pretty noob only been busy with programming couple of months hehe

id like some feedback tho triangles vs quads , pro's and cons other then quads are a asss to wrap textures around lol for some strange reason , seriously i went over to triangles and it worked straight away ? whats that all about lol !!! whats the diff anyway it all comes back to a triangle in the end dont it ? hmm anyway

you can see this as fixed i geuss tnx

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!