#### Archived

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

# Rotating Texture on a Terrain

## Recommended Posts

I am trying to render different textures on a terrain using DrawIndexedPrimitive for speed. The problem is that because the vertices are shared, the texture has to flip in order to be draw correctly. See this for an example, a 2 by 2 terrain: http://www.mobilesolutions.com/home/Image2.jpg How can I get the textures the keep orientation with a draw indexed primitive call without loading 4 of each texture? Sorry if this question is basic, I am just starting on the road to frustration. Thanks!

##### Share on other sites
The way I handled this is to just use 6 vertices and pass in all 6 to the index buffer. You could just use 4 if you have culling turned off and use triangle_strips...because I think half of the quad will get culled if you have culling on for triangle_strips. I don''t know for sure. I think it''s less memory intensive to copy an index buffer with 6 DWORDs per quad than copy 6 vertex structures per quad to recreate a vertex buffer. I couldn''t swear to that, but it seems like it would be.

You can''t save vertices when you tile like this, because like you said each vertex will have a different texture coordinate.

The only savings that you gain from index buffers will come with something like a mesh with a single texture applied to it (a terrain). There could be a lot of shared vertices, but the tex coord is the same for all of the shared vertices in a given spot, so it works okay.

Hope that helps,
Chris

##### Share on other sites
Find a texture that wraps properly and you won''t have to worry about it.

##### Share on other sites
Thanks for the Reply Supernat02, I am starting to change my index buffer and vertex buffer routine to accomodate the changes, my normals are all crazy now so I have some bizzare shading I have to work with.

Raloth, My texture wraps fine, the problem is that the texture is being mirrored and flipped instead of wrapping.

Feeding DirectX approx 2x the number of vertices per terrain seems intensive, but at least I can get it working =)

##### Share on other sites
Ummm...?

If you have vertices like this:

. . . . .. . . . .. . . . .. . . . .. . . . .

You can give them texture coordinates like this:

0,0 1,0 2,0 3,0 4,0 5,00,1 1,1 2,1 3,1 4,1 5,10,2 1,2 2,2 3,2 4,2 5,20,3 1,3 2,3 3,3 4,3 5,30,4 1,4 2,4 3,4 4,4 5,40,5 1,5 2,5 3,5 4,5 5,5
Assuming you haven''t changed any of the wrapping settings, that should take care of everything for you without you having to duplicate vertices.

##### Share on other sites
Artists know how to create textures that tile correctly (left edge matches up with right edge; top with bottom). Thus, you don''t need to duplicate vertices; just keep going on the tiling.

Beware that some graphics cards start having poor precision after about 32x tiling, so don''t go overboard; you gotta restart from 0 (or -32) at some point.

##### Share on other sites
Thanks Raloth,
It seems glaringly obvious now but I was in the middle of all sorts of bizzare workarounds to get that to work!

• ### Forum Statistics

• Total Topics
628394
• Total Posts
2982431

• 10
• 9
• 19
• 24
• 9