Login  Register

Re: VBOs Do TexCoords align to indices or vertices?

Posted by millerni456 on Oct 01, 2011; 9:05pm
URL: https://forum.jogamp.org/VBOs-Do-TexCoords-align-to-indices-or-vertices-tp3384359p3385872.html

Thanks for your input. The reason why I thought I could use 8 vertices and 36 indices is because of this:

I would have 1 vertex corresponding to one of the 8 corners on the cube. (8 Total).
Then since I'm using GL_TRIANGLES each triangle will require a unique set of 3 indices.

So for the front face say has the first four vertices (0,1,2,3). And the back face has (4, 5, 6, and 7).

My first two triangles will be on the front face and use the indices (0, 1, 2,   0, 1, 3)
Lets just say we aren't worried about the order of the indices pointing clockwise/counter-clockwise for now.
The first 3 indices creates half of the square, and the last three create the other half.

  0----3
  |      |
  2----1

Using this same method I'll specify the indices for all the other triangles on each face of the cube.
This totals 2 triangles for face. And 6 faces for the cube, which is 12 triangles. Each triangle has 3 indices (vertices),
which totals to 36 elements in my index array.

So you see how I came up with that.

Now, I wanted to texture this, so obviously I'd need more than 8 vertices to specifiy texCoords to cover the whole cube.
8 vertices is two faces at most textured if the texCoords correspond like such:

Textures are 2D:
{0,0,      0,1,      1,1,       1,0} or something similar (this is 4 sets of 2-Component texCoords).
Then to match this with vertices:
{0, 1, 0,      0, 0, 0,     0, 1, 0,    1, 1, 0} (this is 4 sets of 3 component vertices).

So each set of texCoords matches each set of vertices.

I was wondering if I could format my texture array so that each texCoord matches each index like such:

TexCoords  2D:
{0,0,     1,1,      0,1,       0,0    1, 1,     1, 0,... } (this is 6 sets of 2-Component texCoords).
Indices:
{0, 1, 2, 0, 1, 3, ...} (this is 6 sets of 1 component indices).

I hope this clarifies. From the way I read your post it seemed like we weren't on the same page.