views:

41

answers:

1

Hi!

I'm drawing a simple cube using 8 vertices and 36 indices. No problem as long as I don't try to texture it.

However I want to texture it. Can I do that with only 8 vertices? It seems like I get some strange texture behaviour. Do I need to set up the cube with 24 vertices and 36 indices to be able to texture the cube correctly?

It just doesn't make sence to use vertices AND indices to draw then. I could just as well use vertices only.

+3  A: 

One index refers to one set of attributes (vertex, normal, color, edge flag, etc). If you are willing to have the texture mirrored on adjacent faces of the sides of your cube, you could share both texture and vertex coordinates for the sides. However, the top and bottom faces sharing those same coordinates would not work -- one axis of the texture coordinate would not vary. Once you add other attributes (normal in particular) then a cube would need 24 individual indexes (each with vertex, texture and normal) to have "flat" sides.

Another approach that may work for you is texture coordinate generation. However, needing 24 individual vertices for a cube is perfectly normal.

Ben Jackson
Thanx! I'm thinking why need indices at all? Why not just only use vertcies? It's OpenGL ES which is supposed to be running on mobile devices with limitied memory. Having one buffer for vertcies and one for indices seems like to much.
Espen
The cube is a corner-case (pun not intended). Most meshes are way more complex and tesselated, and therefore benefit from using strips, fans and indexing since you need to copy less data.
Mads Elvheim
"Why not only use vertices?" That's exactly what `glDrawArrays` does.
Ben Jackson
@ Ben: Nice. None of the tutorials about OpenGL ES I've read said anything about glDrawArrays. I think they are to much into it by doing it the right way using indices and vertices. I'll do a test and see what I get both ways. Thanx!
Espen