Skip to content
Overv edited this page Oct 3, 2012 · 4 revisions

This article describes how to use an element buffer for drawing.

Creating the buffer

Creating the buffer containing the array with indices is exactly the same as creating a normal vertex buffer.

unsigned short indices[] = {
	0, 1, 2,
	2, 3, 0
};
GL::VertexBuffer ebo( indices, sizeof( indices ), GL::BufferUsage::StaticDraw );

Binding an element buffer

The new vertex buffer contains the 4 corners of a quad on the Z plane now. To activate a buffer as element buffer, it has to be bound to a VertexArray object.

vao.BindElements( ebo );

As long as an element buffer is bound to a VAO, it will be used for all drawing operations involving elements with the VAO bound.

Drawing

When an element buffer has been bound to a VertexArray instance, it can be used with DrawElements as follows:

gl.DrawElements( vao, GL::Primitive::Triangles, 0, 6, GL::Type::UnsignedShort );

The type of the indices has to be explicitly specified here, it is not remembered. If you want to ignore the element buffer, simply use DrawArrays instead.

Clone this wiki locally