2010-07-16 19 views
1

如果讓我們說2個數組(一個用於法線,一個用於頂點)並使用在頂點和法線之間交錯的索引緩衝區,可以使用glDrawElements方法嗎?glDrawElements索引應用於頂點和法線

例子:渲染立方

// 8 of vertex coords 
GLfloat vertices[] = {...}; 
// 6 of normal vectors 
GLfloat normals[] = {...}; 
// 48 of indices (even are vertex-indices, odd are normal-indices) 
GLubyte indices[] = {0,0,1,0,2,0,3,0, 
        0,1,3,1,4,1,5,1, 
        0,2,5,2,6,2,1,2, 
        1,3,6,3,7,3,2,3, 
        7,4,4,4,3,4,2,4, 
        4,5,7,5,6,5,5,5}; 
glEnableClientState(GL_VERTEX_ARRAY); 
glEnableClientState(GL_NORMAL_ARRAY); 
glVertexPointer(3, GL_FLOAT, 0, vertices); 
glNormalPointer(3, GL_FLOAT, 0, normals); 
glDrawElements(GL_QUADS,...);//?see Question 
+0

[Rendering mesh with multiple indices]的可能重複(http://stackoverflow.com/questions/11148567/rendering-meshes-with-multiple-indices) – 2013-01-17 15:48:50

回答

4

沒有,看到glDrawElements()documentation

只能通過使用交錯數據(未交叉索引)實現 '交錯',或者通過glInterleavedArrays(見here):

float data[] = { v1, v2, v3, n1, n2, n3 .... }; 
glInterleavedArrays(GL_N3F_V3F, 0, data); 
glDrawElements(...); 

或通過:

float data[] = { v1, v2, v3, n1, n2, n3 }; 
glVertexPointer(3, GL_FLOAT, sizeof(float) * 3, data); 
glNormalPointer(3, GL_FLOAT, sizeof(float) * 3, data + sizeof(float) * 3); 
glDrawElements(...); 

,你可以看到,glInterleavedArrays()只是glInterleavedArrays()和朋友的一些糖。

+0

爲了記錄,'glVertexPointer'和'glNormalPointer '應該是'sizeof(float)* 6',數據向量定義爲'{v1,v2,v3,n1,n2,n3 ....}'。 – AldurDisciple 2014-11-17 16:24:45

相關問題