我想使用一个顶点数组和一个法线数组生成一个多维数据集,但要避免重复每个法线坐标。是否有类似的方法可以执行类似glDrawElements()的操作,但对于普通数组呢?
GLfloat vertices[] = {
-0.5, -0.5, 0.5,
0.5, -0.5, 0.5,
0.5, 0.5, 0.5,
-0.5, 0.5, 0.5,
-0.5, -0.5, -0.5,
-0.5, 0.5, -0.5,
0.5, 0.5, -0.5,
0.5, -0.5, -0.5,
}; // 8 cube vertex
GLubyte indices[] = {
0, 1, 2, 3, // 24 indexes
4, 5, 6, 7,
7, 6, 2, 1,
0, 3, 5, 4,
0, 4, 7, 1,
2, 6, 5, 3};
float normals[] = {
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, -1.0f,
1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, -1.0f, 0.0f}; //6 normals for each vertex
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(GL_FLOAT, 0, normals);
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, indices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);