我在不同的在線網站上看到不同數量的頂點來表示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