texture mapping on indexed primitives?

Started by
4 comments, last by Illco 18 years, 8 months ago
Hi! A long time I was trying to find a tutorial on how to map a texture on a primitive built with index buffer. All I could find was a note that there is a disadvantage of the index buffers, which can not allow us to map textures correctly. So, my first question: What are index buffers good for when I can't put a texture on my cube correctly? The second question: Is there a way to avoid this disadvantage? If so, pleeease share your ideas on it. Or should I build my cube with a vertex buffer only? What about more complex models? Thanx a lot in advance! SONB
Advertisement
Quote:
All I could find was a note that there is a disadvantage of the index buffers, which can not allow us to map textures correctly.

This is absolute BS nonsense. What is the problem that would make this impossible? I cannot even answer your second question because I cannot think of any. The only issue is that some positions need to be repeated because two faces may use a vertex differently (i.e. with different texture coordinates) but this is easily fixed. See this recent thread.

Greetz,

Illco
Well, this article http://www.gamedev.net/reference/articles/article1247.asp says:

Quote:Note, you are not reusing the vertices as described in example three. This is because you need up to three texture coordinates per vertex and you only have specified the one.


So, what should I do, when I'm reusing the vertices?


Sorry, I'm just a newbie asking newbie-questions...



SONB
I don't see why the author did it that way other then for the sake of writing the text more quickly. You can simply do that as you'd expect: define three texture coordinates per vertex and index the vertices... There is really not much to it.

Greetz,

Illco
Thanx for your reply Illco!

I defined three coordinates for each vertex, changed my vertex array and FVF flags like this:

#define D3DFVF_CUSTOM (D3DFVF_XYZ | D3DFVF_TEX3)

typedef struct
{
FLOAT x, y, z;
FLOAT u1, v1;
FLOAT u2, v2;
FLOAT u3, v3;
} CUSTOMVERTEX;

Now how can I tell the app to use the right coordinates? I just want to map the same texture onto each side of my cube.

SONB
Ok perhaps I wrote a bit confusingly but for a cube you do not need three texture coordinates per vertex. What the author of the tutorial was trying to do, I don't know, but he/she thought it require three texture coordinates. For a cube we do not.

Although there are only eight positions (corner points) they are all used three times with at least different normals. So we need 24 vertices. The normals should point in the direction of the side and the texture coordinates should run from (0,0) to (1,1) accross a side.

I don't know whatever vertex you had before but it is probably fine for this. The right values for a cube you can find on the net.

Greetz,

Illco

This topic is closed to new replies.

Advertisement