Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Dragun

Terrain texturing problems

This topic is 5559 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

Ok, either I'm not thinking clearly or just not "getting" it. I have this terrain engine and it renders nice and spiffy. It loads up a .raw file for the heightmap and the like. My question is how should I approach the algorithm to texture the terrain so that I will not get mirrored textures? Check this screen:
Notice how the texture is mirrored (it's an M). If I have [1] at texture coordinate (0,0) and [4] at (1,1), then the next quad left and down will have the starting texture coordinate of [4]. Damn, does this makes sense? 1---2 |....| (one quad) 3---4 1---2---? |....|....| 3---4---? (four quads) |....|....| ?---?---? What should I fill the [?] with? [edited by - Ðragun on April 2, 2003 2:37:36 AM]

Share this post


Link to post
Share on other sites
Advertisement

If you are using regular quads, you redefine texture coordinates for each quad- at least that''s how I do it

1---2,1---2
|.a..|..c.|
3,1---4,2,3,1---2 (four quads)
|.b..|.c..|
3---4,3---4


for quads defined in order a,b,c,d. ie each one has
1---2
3---4


If you are using quad strips:

1---2,1---2
|.a.|.d.|
1---2,1---2 (four quads)
|.b..|..c.|
1---2,1---2

ie down a,b up c,d

Share this post


Link to post
Share on other sites
If you''re using DirectX you should turn on tiling (might be called wrapping) for textures. This means that you can use texture coordinates < 0 and > 1 and they will refer to a texture map consisting of tiled copies of your texture without any mirroring.

Share this post


Link to post
Share on other sites
I''m using triangle strips where it''s just a plain grid defined as quads (all quads share vertices with another quad). How should I approach this? Redefine my U,V coordinates?

Share this post


Link to post
Share on other sites
Set your texture coord mode to WRAP, then you can do:


0,0---0,1---0,2
|......|......|
1,0---1,1---1,2 (four quads)
|......|......|
2,0---2,1---2,2

Share this post


Link to post
Share on other sites
For my engine, and I'm not sure why exactly this works (I use OpenGL), but it tiles the textures nicely per quad with no mirroring and you can use efficiently vertex arrays because the texture coords are per vertex. Here is the code:


          
int width, length; //width and length of the terrain in vertices

TEXCOORD texCoords[width*length]; //TEXCOORD is just a struct with a float u,v;


//this loop isn't optimized

for(int z=0 ; z < width ; z++)
{
for(int x=0 ; x < length ; x++)
{
texCoords[z * width + x].u = (float)x;
texCoords[z * width + x].v = (float)z;
}
}

And that should give you texcoords per vertex to tile without mirroring and be able to use vertex arrays. When you go to render, just make sure texcoord[0] corresponds to vertice[0], and texcoord[1] corresponds to vertce[1] . . . texcoord[n] corresponds to vertice[n].


Hope that helps!


-------------------
Realm Games Company

[edited by - greatone on April 2, 2003 5:41:19 PM]

Share this post


Link to post
Share on other sites

  • 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!