Graphics Programs Reference
In-Depth Information
Note
Do not confuse OpenGL ES buffer objects with
java.nio.*Buffer
objects, such as
java.nio.ShortBuffer
,
java.nio.FloatBuffer
, and
so on.
Listing 5-1.
TANK FENCE 1/src/com/apress/android/tankfence1/GLES20Ren-
derer.java
GLES20.glGenBuffers(2, _tankBuffers, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER,
_tankBuffers[0]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER,
tankVFA.length * 4, _tankVFB, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER,
_tankBuffers[1]);
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER,
tankISA.length * 2, _tankISB, GLES20.GL_STATIC_DRAW);
Finally, after making a buffer object the current buffer object, we need to pass
it the corresponding vertex or index data using the ES 2.0 function
glBuffer-
Data
. As shown in
Listing 5-1
, after the call to
glBindBuffer(GLES20.GL_ARRAY_BUFFER, _tankBuffers[0])
,
glBufferData
is called, with arguments
"GLES20.GL_ARRAY_BUFFER"
,
"tankVFA.length
4"
,
"_tankVFB"
,
and
*
"GLES20.GL_STATIC_DRAW"
.
As with
glBindBuffer
, the first argument passed to
glBufferData
is either
GL_ARRAY_BUFFER
or
GL_ELEMENT_ARRAY_BUFFER
, denoting the target/
type of the buffer object. The second argument denotes the size of array (of per-
vertex or index data) in bytes. The third argument denotes the
Buffer
(
java.nio.Buffer
) for the corresponding vertex or index data. Finally, the last
argument can be any one of the following values:
▪
GL_STATIC_DRAW
▪
GL_DYNAMIC_DRAW
Search WWH ::
Custom Search