Graphics Programs Reference
In-Depth Information
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 4);
}
The call to ES 2.0 functions—
glVertexAttribPointer
and
glEnableVer-
texAttribArray
(and others explained in the following section)—inside
onDrawFrame
is sandwiched between function calls for using an ES 2.0
program
glDrawElements
). This must be done every time we render an object (that is, a
primitive or a combination of same type of primitives).
glDrawArrays
. This method takes three arguments—
mode
,
first
, and
count
—all of type
int
. Using
mode
, we specify the type of primitive we want
to render. We work with modes
GL_POINTS
,
GL_LINES
, and
GL_TRIANGLES
,
but please be aware that ES 2.0 also provides alternate modes (
GL_LINE_STRIP
,
GL_LINE_LOOP
,
GL_TRIANGLE_STRIP
, and
GL_TRIANGLE_FAN
).
GL_POINTS
mode is very straightforward. By calling
glDrawAr-
rays(GLES20.GL_POINTS, 0, 4)
, we notify the vertex shader that we want
to render four points (point sprites) on the OpenGL surface. The second argument
is '0,' because we want to render from the first vertex inside
pointVFA (0.1f,
0.1f, 0.0f)
in
Listing 3-17
.
Similarly, for rendering a line primitive, we call
glDrawAr-
rays(GLES20.GL_LINES, 0, 2)
, and for a triangle primitive, we call
glDrawArrays(GLES20.GL_TRIANGLES, 0, 3)
. Next, I'll show you how
to render a line, triangle, and rectangle using
glDrawArrays
.
Drawing Line and Triangle Primitives
For the following applications, you may use the
GL POINT ADVANCED
application
using
glDrawArrays
method, we must make sure we set its mode argument as
GLES20.GL_LINES
. Since a line requires two points, while rendering a line prim-
itive, the count argument (the last argument in the
glDrawArrays
method) should
be at least '2.'
Search WWH ::

Custom Search