VBOs Do TexCoords align to indices or vertices?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

VBOs Do TexCoords align to indices or vertices?

millerni456
This post was updated on .
EDIT: The answer is vertices.

The subject displays my question. I'm just trying to find out if the texture coordinates
correspond to the indices, or the vertices (in regards to using Vertex Buffer Objects).

I'm trying to make a cube with 8 vertices and 36 indices (because I'm using GL_TRIANGLES).

I thought that if I had 8 texture coordinates, then my whole cube wouldn't render with textures.
So...Do i need 36? or how does this work?

Thanks in advance!

-Nick.
Reply | Threaded
Open this post in threaded view
|

Re: VBOs Do TexCoords align to indices or vertices?

gouessej
Administrator
Hi

You need at least 24 vertices (4*6) or 36 vertices (6*6) if you don't use indices. The texture coordinates corresponds to the vertex coordinates. If you use several VBOs (one for the texture coordinates, another one for the vertex coordinates, another one for the normals, etc...), the second texture coordinate ([u,v] in 2D) matches with the second vertex coordinate ([x,y,z] in 3D). When you use an index buffer, a given index designates a vertex in all the bound buffers (texture, vertex, normal, color, fog, etc...). Best regards
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: VBOs Do TexCoords align to indices or vertices?

millerni456
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.
Reply | Threaded
Open this post in threaded view
|

Re: VBOs Do TexCoords align to indices or vertices?

millerni456
In reply to this post by gouessej
Perhaps I answered my question by attempting to fix a bug.

I attempting to create my arrays the way I specified. And the glBufferData has a bad reaction to my extremely large texCoord buffer.

So I lessened it to 8 sets of 2-Component texCoords (matching vertices) and I get no more error.