我在不同的在线网站上看到不同数量的顶点来表示OpenGL ES中的同一个立方体。 例如,这是一个:在OpenGL ES中绘制立方体需要多少顶点?
float vertices[] = { -width, -height, -depth, // 0
width, -height, -depth, // 1
width, height, -depth, // 2
-width, height, -depth, // 3
-width, -height, depth, // 4
width, -height, depth, // 5
width, height, depth, // 6
-width, height, depth // 7
};
short indices[] = { 0, 2, 1,
0, 3, 2,
1,2,6,
6,5,1,
4,5,6,
6,7,4,
2,3,6,
6,3,7,
0,7,3,
0,4,7,
0,1,5,
0,5,4
};
这里是另一个问题:
float vertices[] = {
//Vertices according to faces
-1.0f, -1.0f, 1.0f, //Vertex 0
1.0f, -1.0f, 1.0f, //v1
-1.0f, 1.0f, 1.0f, //v2
1.0f, 1.0f, 1.0f, //v3
1.0f, -1.0f, 1.0f, //...
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
};
这表示是在OpenGL ES最高性能(注意,这是OpenGL ES的,而不是OpenGL的)?当我想为光线指定法线时,这是最好的表现形式。在我的另一篇文章中,我得到的印象是我需要为立方体指定24个顶点,另一个说我需要36个顶点,而另一个说我需要一个不同的数字来获得相同问题的矛盾答案。无论如何,我想知道正确的单一答案,技术上是正确的。
我知道有一个三角地带或三角风扇等的概念,绘制但对我来说,我使用:
gl.glDrawElements(GL10.GL_TRIANGLES, mNumOfIndices,
GL10.GL_UNSIGNED_SHORT, mIndicesBuffer);
所以这应明确澄清我问。
如果立方体因面对面而不同,则可能需要额外的顶点。例如,每个面上具有不同颜色的立方体可能需要24个顶点,如果使用glTriangles绘制,则需要36个索引。如果不是立方体的所有边都可见,则可以通过不绘制不可见的面来优化绘图,从而减少索引计数。 – 2011-02-17 19:13:34