Graphics Reference
In-Depth Information
a
vec2
variable using the
mediump
precision qualifier. The values assigned
to
gl_PointCoord
go from 0.0 to 1.0 as we move from left to right or
from top to bottom, as illustrated in Figure 7-3.
(0, 0)
(1, 0)
(0, 1)
(1, 1)
Figure 7-3
gl_PointCoord
Values
The following fragment shader code illustrates how
gl_PointCoord
can
be used as a texture coordinate to draw a textured point sprite:
#version 300 es
precision mediump float;
uniform sampler2D s_texSprite;
layout(location = 0) out vec4 outColor;
void main()
{
outColor = texture(s_texSprite, gl_PointCoord);
}
There are five API calls in OpenGL ES to draw primitives:
glDrawArrays
,
glDrawElements
,
glDrawRangeElements
,
glDrawArraysInstanced
, and
glDrawElementsInstanced
. We will describe the first three regular non-
instanced draw call APIs in this section and the remaining two instanced
draw call APIs in the next section.
glDrawArrays
draws primitives specified by
mode
using vertices given by
element index
first
to
first + count - 1
. A call to
glDrawArrays
(GL_TRIANGLES, 0, 6)
will draw two triangles: a triangle given by element
indices (0, 1, 2) and another triangle given by element indices (3, 4, 5).
Similarly, a call to
glDrawArrays(GL_TRIANGLE_STRIP, 0, 5)
will draw
three triangles: a triangle given by element indices
(
0, 1, 2), the second
triangle given by element indices (2, 1, 3), and the final triangle given by
element indices (2, 3, 4).