Graphics Programs Reference
In-Depth Information
Types of Buffer Objects
There are two types of vertex buffer objects— array buffer objects and element array
buffer objects . The array buffer objects are used to cache the per-vertex data, such as
vertices {x, y, z} , colors {r, g, b, a} , normals {Nx, Ny, Nz} , and so
on, and the element array buffer objects are used to cache the corresponding indices
of these arrays.
Using Buffer Objects
To use buffer objects, we first need to generate them. To do this, call the method
GLES20.glGenBuffers . This method has two overloaded versions. The one we
use here takes three arguments:
▪ The first argument specifies the number of buffer objects that
must be generated.
▪ The second argument specifies the array to store the returned (in-
teger) ids, representing objects. Please note that the id “0” is re-
served by OpenGL ES.
▪ The third argument specifies the offset of type int . For all ex-
amples discussed, we set this argument to “0”, meaning “no-off-
After generating buffer object(s), call the method GLES20.glBindBuffer . This
method is used to make a buffer object the current array buffer object or the current
element array buffer object .
So, depending on the use of the buffer object, the first argument passed to this
method is either GLES20.GL_ARRAY_BUFFER or
GLES20.GL_ELEMENT_ARRAY_BUFFER . The second argument passed to this
method is the id of the buffer object, as shown in Listing 5-1 . Here,
_tankBuffers is an int array of size 2. The size is 2, because we need two buf-
fer objects.
Search WWH ::

Custom Search