Sign in to follow this  

Indexbuffers + texturing???

Recommended Posts

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!

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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 format
struct MyVertex
float x, y, z;
float u0, v0;
float u1, v1;
VertexFormat Format = VertexFormats.Position | VertexFormats.Texture0
| VertexFormats.Texture1;

// choose which one to use
device.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]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this