Computergrafik
VBOs mit OpenGL
← Native VBOs | ● | Mehrere VBOs →
Beispiel für VBOs mit plain OpenGL:
Hinweis: Nur für die Akten! Zu umfangreich und fehleranfällig, um das ohne Zwischenschicht wie LGL, Godot oder Unreal praktikabel verwenden zu können.
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};
// fill buffers
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);
// render buffers
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)));
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};
// fill buffers
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);
// render buffers
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)));
← Native VBOs | ● | Mehrere VBOs →