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]
Terrain texturing problems
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
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.
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?
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
0,0---0,1---0,2
|......|......|
1,0---1,1---1,2 (four quads)
|......|......|
2,0---2,1---2,2
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:
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]
int width, length; //width and length of the terrain in verticesTEXCOORD texCoords[width*length]; //TEXCOORD is just a struct with a float u,v;//this loop isn't optimizedfor(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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement