Texture coords and vertex arrays question.

  1. Assume the object having textures mapped to it
    is a cube, so there are 6 verticies involved.
  2. Assume I’m going to use one texture for all sides.

My problem is this:

  1. Every vertex is shared by 3 faces of the cube.
  2. It seems you can only map ONE texture corner
    to each vertex.
  3. Because of this, one of the 3 faces has the correct
    corner of the texture mapped to it, and the other
    2 faces which share the vertex have the incorrect
    corneer of the texture mapped to it.

In short, how do you use vertex arrays to achieve the same results as using glBegin() and glEnd() as in NeHe’s lesson 6? with the wooden box?

Thanks :slight_smile:

As far as I can see, the only way is to duplicate the vertices. Btw: thats pretty much what happens when using glVertex3f anyway.

Jan

Wouldn’t duplicating the verticies defeat the purpose of using vertex arrays (re-using already stored verticies)?

I’m a newbie, so maybe I just don’t get it:)

What does everyone else do?

had that problem too.

what you could try is to re-render the texture so that every vertex only needs one texcoord. make one texture cover the whole box (the texture would look like a “+” made out of 6 boxes), so you can wrap it around.
i didn’t try it, but it may be possible to do this via texcoords > 1

[quote]Wouldn’t duplicating the verticies defeat the purpose of using vertex arrays (re-using already stored verticies)?

I’m a newbie, so maybe I just don’t get it:)

What does everyone else do?
[/quote]
Since you need several texCoord, your only option is using several vertices. (Multitexturing won’t help you here - at least not performance-wise - since then, you are applying all six textures to all faces).

If you don’t use lighting, the vertex-processing part is very small anyway and if you use lighting, you would need several normals per vertex as well (one for each face the vertex is part of), if you want to keep the edges and not have something that has the outline of a box but the shading of a very weird sphere.

The reuse only makes sense, if the vertices don’t mark hard edges but rather support a curved surface (NOT in the NURBS meaning) or if you want to tesselate a plane in order to get better specular hightlight.

Concerning HamsterofDeath’s suggestions, yep you could just use one single texture for all faces, where you set up your texture-coordinate up accordingly. This is what you would for example do with more complex models anyway, you don’t have a texture for every face. The only drawback is of course, that your texture-resolution is more limited, but unless you want your cube to fill almost the entire screen, no problem there.

Jan

Well, there you have it: a clear explaination, and another of my problems solved.

Thank you, sir :slight_smile:

No problem ;D

Thanks from me too, because this had been bugging me for some time as well :slight_smile: