Rotating Texture on a Terrain

Started by
5 comments, last by perallen 20 years, 3 months ago
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!
Advertisement
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
Chris ByersMicrosoft DirectX MVP - 2005
Find a texture that wraps properly and you won''t have to worry about it.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
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 =)
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.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
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.
enum Bool { True, False, FileNotFound };
Thanks Raloth,
It seems glaringly obvious now but I was in the middle of all sorts of bizzare workarounds to get that to work!

This topic is closed to new replies.

Advertisement