我想知道有没有人能帮我理解索引如何处理glDrawElements。在下面的例子中(从http://www.everita.com/lightwave-collada-and-opengles-on-the-iphone取)作者提到,你只能有一个索引集,在这种情况下OpenGL ES - glDrawElements - 故障理解索引
const GLushort tigerBottomIndices[] = {
0,1,2,
3,0,4,
1,5,6,
…
};
我的问题是这些指数描述的是什么?我是否认为前三个是顶点位置,后三个是相应的法线,最后三个是纹理合成?
在此先感谢!
#import "OpenGLCommon.h"
const Vertex3D tigerBottomPositions[] = {
{0.176567, 0.143711, 0.264963},
{0.176567, 0.137939, 0.177312},
{0.198811, 0.135518, 0.179324},
…
};
const Vertex3D tigerBottomNormals[] = {
{-0.425880, -0.327633, 0.350967},
{-0.480159, -0.592888, 0.042138},
{-0.113803, -0.991356, 0.065283},
…
};
const GLfloat tigerBottomTextureCoords[] = {
0.867291, 0.359728,
0.779855, 0.359494,
0.781798, 0.337223,
…
};
const GLushort tigerBottomIndices[] = {
0,1,2,
3,0,4,
1,5,6,
…
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, tigerTextures[5]);
glVertexPointer(3, GL_FLOAT, 0, tigerBottomPositions);
glNormalPointer(GL_FLOAT, 0, tigerBottomNormals);
glTexCoordPointer(2, GL_FLOAT, 0, tigerBottomTextureCoords);
glDrawElements(GL_TRIANGLES, 210, GL_UNSIGNED_SHORT, tigerBottomIndices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableEnableClientState(GL_TEXTURE_COORD_ARRAY);
谢谢 - 我需要的确切解释。 – GuybrushThreepwood 2012-02-14 16:08:43
我见过的最好的解释之一。 Thx – 2012-06-12 21:42:48
很好的解释 – dbryson 2012-10-11 00:35:48