question about the shiny teapot

I had a question about shiny teapot demo. Provided are “teapotPositions” and “teapotIndices”, among others.

I’m trying to extract the “faces” of the teapot. The way I’m interpreting the “indices” is that they describe the faces of the teapot; each face is a triangle and each vertex of the triangle is given by the vertex indices.

For example…

   0,1,2,    // face 1
   2,3,0,    // face 2

… (0,1,2) are the indices into the “positions” array and correspond to a face of the teapot and these indices correspond to these 3 vertices:

v1 = (5.929688, 4.125, 0)
v2 = (5.387188, 4.125, 2.7475)
v3 = (5.2971, 4.494141, 2.70917)

… which are the first 9 entries in the “positions” array.

I guess my question is, what do the vertex indices correspond to? Does a ’0? in the indices array correspond to the first 3 entries in the positions array? Am I understanding things correctly? If my understanding is incorrect, how would I figure out the faces (triangles) of the teapot?


Look at the specification for glDrawElements in either WebGL, OpenGL ES or OpenGL specifications.

But yes, you’ve understand it correctly, it of course depends on what you specify for the glVertexAttribPointer. You give it a size, which is either 2,3 or 4. This is the number of floats for every vertex. In your case it is 3. Thus for every three floats in your array, you have a vertex.

And as you said, the index is referencing a vertex in your vertex array, thus index 0 is the first vertex, the first 3 floats. Index 1 would be the 3 following vertices, etc etc…

Notice however that it is often the case that you use vec4 (or vec2 when doing 2D stuff, or texture coordinates to name a few).