2010-07-16 24 views
1

Est-il possible d'utiliser la méthode glDrawElements lorsque vous avez disons 2 tableaux (un pour les normales et un pour les sommets) et utilisez le tampon d'index intercalé entre les sommets et les normales).glDrawElements avec des index appliqués aux sommets et aux normales

Exemple: le rendu d'un cube

// 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

duplication possible de [Rendu de maillages avec plusieurs index] (http://stackoverflow.com/questions/11148567/rendering-meshes-with-multiple-indices) –

Répondre

4

Non, voir le documentation de glDrawElements().

Vous ne pouvez réaliser 'désentrelacement' en utilisant des données intercalées (non indices intercalées), soit par glInterleavedArrays (voir here):

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

ou via:

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(...); 

comme vous pouvez le voir , glInterleavedArrays() est juste un peu de sucre autour de glInterleavedArrays() et amis.

+0

Pour la notice, la foulée dans 'glVertexPointer' et' glNormalPointer 'devrait être' sizeof (float) * 6' avec le vecteur de données défini comme '{v1, v2, v3, n1, n2, n3 ....}'. – AldurDisciple