GL_TEXTURE_COORDS_ARRAY

Started by
3 comments, last by TomasH 19 years, 8 months ago
hi, I am trying to texture map a cube using VERTEX ARRAYS. i've a an array of 8 elements (cube vertices) and an index array of 24 ( 4 for each face) but I wonder how do I fit my texture coordinates for all 4 faces (24 elements of x,y) glDrawElements would call on the indices array and vertex array would be accessed by means of traversing through the indices array; but how to texture map it ?? thanks, boyd
Advertisement
You could simply store each vertex three times - that way storing the correct texture coordinates would be no problem.
I knew that won't be a problem but Is that the only way it would be done in programs?.

~ boyd
A cube is pretty much the worst case for vertex arrays if you need normals and/or texture coordinates. In a corner of the cube, three faces use the same vertex, so the vertices can be shared. However, the shared vertices usually have different normal/texture coordinate, and that makes the three vertices different, so you can no longer share them in the vertex array.

In short, even though there are only 8 vertices in a cube, the fact that (usually) no shared vertices also share other attributs means you must build the cube from 24 unique vertices.

edit: Bah, must learn to type faster [razz]
I can think of some specific case where you wouldn't need to store the vertices several times - at least not all of them - but generally I don't think there's a way around this. However, since there are so few vertices involved to begin with, this shouldn't be a problem.

This topic is closed to new replies.

Advertisement