Should glVertexPointer contain distinct vertices, or all vertices?
I'm creating an Android app utilising OpenGL ES, and need some help with the vertex, texture and normal pointers. The examples I've seen stop at a fairly basic level so I seem to be missing a bit of information.
My basic draw() process is
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glTexCoordPointer(3, GL10.GL_FLOAT, 0, uvBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, faceBufferLength, GL10.GL_UNSIGNED_BYTE, faceBuffer);
The vertex and uv are FloatBuffers constructed from the various x, y and z coordinates of the respective vertices and uv's.
The faceBuffer
is a ByteBuffer of indices pointing to the relevant vertexBuffer.
Each face consists of three vertices, a开发者_如何学运维nd each face defines a different UV for it's vertices (correct?)
My question therefore is, do I need to re-define each distinct vertex/uv combination in all the buffers?
Consider a simple tetrahedron. It consists of
4 vertices (three 'base' and one 'point'):
Vertex 1: <1,1,1> (the point)
Vertex 2: <2,1,0>
Vertex 3: <0,0,0>
Vertex 4: <2,0,0>
3 uv coordinates (all faces have the same image)
UV 1: <0,0,0> (top left)
UV 2: <0,1,0> (bottom left)
UV 3: <1,0,0> (top right)
4 faces:
Face 1: v1/u1, v2/u2, v3/u3
Face 2: v1/u1, v3/u2, v4/u3
Face 3: v1/u1, v4/u2, v2/u3
Face 4: v2/u1, v3/u2, v4/u3
So my question is, how do I tell GL which UV to use for each face/vertex?
Should vertexBuffer
have 4 sets of values in it, or 12? Must uvBuffer
and vertexBuffer
have the same number of items?
Basically, can I "re-use" vertices if they have different UV and/or normal values?
Or do I have to be unique:
Vertex 1: <1,1,1> (face A)
Vertex 2: <2,1,0> (face A)
Vertex 3: <0,0,0> (face A)
Vertex 4: <1,1,1> (face B)
Vertex 5: <0,0,0> (face B)
Vertex 6: <2,0,0> (face B)
Vertex 7: <1,1,1> (face C)
Vertex 8: <2,0,0> (face C)
Vertex 9: <2,1,0> (face C)
Vertex 10: <2,1,0> (face D)
Vertex 11: <0,0,0> (face D)
Vertex 12: <2,0,0> (face D)
UV 1: <0,0,0> (face A)
UV 2: <0,1,0> (face A)
UV 3: <1,0,0> (face A)
UV 4: <0,0,0> (face B)
UV 5: <0,1,0> (face B)
UV 6: <1,0,0> (face B)
UV 7: <0,0,0> (face C)
UV 8: <0,1,0> (face C)
UV 9: <1,0,0> (face C)
UV 10: <0,0,0> (face D)
UV 11: <0,1,0> (face D)
UV 12: <1,0,0> (face D)
Face 1: v1/u1, v2/u2, v3/u3
Face 2: v4/u5, v5/u5, v6/u6
Face 3: v7/u7, v8/u8, v9/u9
Face 4: v10/u10, v11/u11, v12/u12
Duplicate the position data, as in have 12 vertex positions in vertexData. Do the same for the texture coordinates.
The indices, as you noticed, index all the arrays with the same indices, so it is standard to duplicate the vertex positions so that each index has its own vertex data (position + UV).
精彩评论