Computergrafik
OpenGL Indexed Face Sets
← Batching | ● | OpenGL Legacy Schnittstellen →
Zwei Arrays
- Vertex Liste (Geometrie)
- Face Liste (Topologie)
Beispiel Pyramide mit 5 Eckpunkten (Basis $p_0,p_1,p_2,p_3$ und Spitze $p_4$)
Vertex Liste:
0: $x_0,y_0,z_0$
1: $x_1,y_1,z_1$
2: $x_2,y_2,z_2$
3: $x_3,y_3,z_3$
4: $x_4,y_4,z_4$
Face Liste:
0: 0,1,4
1: 1,2,4
2: 2,3,4
3: 3,0,4
4: 3,2,1,0
Vorteile:
- Speicherplatzersparnis durch einfache Aufzählung jedes Punktes
- Übliches Speicherformat für Dreicksgeometrien (Beispiel: .obj-Dateiformat)
OpenGL (hier noch nicht mit Vertex Buffer Objects):
GLfloat vertex_list[]={-1,-1,0, 1,-1,0, 1,1,0, -1,1,0, 0,0,1.5};
glVertexPointer(3,GL_FLOAT,0,vertex_list);
glEnableClientState(GL_VERTEX_ARRAY);
GLushort element_list[]={0,1,4, 1,2,4, 2,3,4, 3,0,4, 3,2,1,0};
glDrawElements(GL_TRIANGLES,
4*3,GL_UNSIGNED_SHORT,element_list);
glDrawElements(GL_QUADS,
4,GL_UNSIGNED_SHORT,element_list+12);
glVertexPointer(3,GL_FLOAT,0,vertex_list);
glEnableClientState(GL_VERTEX_ARRAY);
GLushort element_list[]={0,1,4, 1,2,4, 2,3,4, 3,0,4, 3,2,1,0};
glDrawElements(GL_TRIANGLES,
4*3,GL_UNSIGNED_SHORT,element_list);
glDrawElements(GL_QUADS,
4,GL_UNSIGNED_SHORT,element_list+12);
Mit VBOs:
GLuint vertex_buffer, element_buffer;
glGenBuffers (1, &vertex_buffer);
glBindBuffer (GL_ARRAY_BUFFER, vertex_buffer);
glBufferData (GL_ARRAY_BUFFER, sizeof (vertex_list), vertex_list, GL_STATIC_DRAW);
glGenBuffers (1, &element_buffer);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, element_buffer);
glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (element_list), element_list, GL_STATIC_DRAW);
glBindBuffer (GL_ARRAY_BUFFER, vertex_buffer);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, element_buffer);
glEnableVertexAttribArray (0);
glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glDrawElements (GL_TRIANGLES, 4*3, GL_UNSIGNED_SHORT, NULL);
glDrawElements (GL_QUADS, 4, GL_UNSIGNED_SHORT, (void *) (4*3*sizeof(unsigned short)));
glGenBuffers (1, &vertex_buffer);
glBindBuffer (GL_ARRAY_BUFFER, vertex_buffer);
glBufferData (GL_ARRAY_BUFFER, sizeof (vertex_list), vertex_list, GL_STATIC_DRAW);
glGenBuffers (1, &element_buffer);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, element_buffer);
glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (element_list), element_list, GL_STATIC_DRAW);
glBindBuffer (GL_ARRAY_BUFFER, vertex_buffer);
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, element_buffer);
glEnableVertexAttribArray (0);
glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glDrawElements (GL_TRIANGLES, 4*3, GL_UNSIGNED_SHORT, NULL);
glDrawElements (GL_QUADS, 4, GL_UNSIGNED_SHORT, (void *) (4*3*sizeof(unsigned short)));
← Batching | ● | OpenGL Legacy Schnittstellen →