Indexbuffers + texturing???

Started by
1 comment, last by gibson 19 years, 8 months ago
I have just crawled through a indexbuffer tutorial and I wonder how could I add some texture to this in the best way, I mean sometimes you would like to use different texture coordinates while you use the same vertexes. Should I create some face or polygon class that’s saving the index to the vertexes and the texture coordinates? Please help me!
Advertisement
I have yet to find a way to actually do what you want. If a vertex is shared, and needs two different texture coordinates, then you're simply going to need two vertices.

I was hopeful while reading about streams in DX9. They let you split up your buffers, so that you can have a stream for position, and stream or texture coordinates, a stream for normals, etc. However, you can still only use one index buffer, and the indices are applied to each stream the same. If in future versions you could have an index buffer associated with each stream, then a solution to this problem would be gained. However, that would also mean that there might be a lot more indices, and thus the bandwidth trade-off might not be worth it. For now, I suppose, just duplicate the vertex and not fret over it too much.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
You should be able to do this by defining a custom vertex format that contains multiple texture coordinates and then using one of the DX functions to choose which set to use. I believe there are bitflags in the FVF format for something like 8-10 texcoords per vertex. You might also look into texture matrix transformations, but I'm not sure if they're really supported by DirectX.

If you're using managed C# DX9, it would be something like this (similar for C++ I'm sure):

// define a custom formatstruct MyVertex{float x, y, z;float u0, v0;float u1, v1;VertexFormat Format = VertexFormats.Position | VertexFormats.Texture0| VertexFormats.Texture1;};// choose which one to usedevice.TextureState[0].TextureCoordinateIndex = 0;


Edited by Coder: Source tags are cool. Syntax highlighting is relieves the eye

[Edited by - Coder on August 3, 2004 4:46:09 PM]

This topic is closed to new replies.

Advertisement