Graphics Programs Reference
In-Depth Information
Figure 3-11 . Line primitive
After appropriately setting the arguments for glDrawArrays , we must create an
array to store the endpoints of line(s). So, inside the template you can modify the
contents of the float array pointVFA (inside initShapes method), and, to
get an output similar to Figure 3-11 , define this array as {0.0f,0.0f,0.0f,
0.5f,0.5f,0.0f} . Since this array has two points, we must call glDrawAr-
rays using glDrawArrays(GLES20.GL_LINES, 0, 2) .
Before you run this application, remove the line “ gl_PointSize = 15.0;
from the vertex shader. As previously stated, gl_PointSize variable is only
used with a point sprite primitive. To set the width of line primitive, call the
method GLES20.glLineWidth(float
width) before
calling
GLES20.glDrawArrays . The default width is 1.0.
Varyings
Like vertex shaders, fragment shaders have a special kind of input variable, called
varying . They are special, because they are used to store the output of the vertex
shader, as well as the input of a fragment shader.
Varyings interpolate values across a primitive, and this becomes useful when creating
cool gradients (as shown in Figure 3-12 ) or interpolating texture coordinates and nor-
mals (as we see in Chapter 5 ) .
 
 
Search WWH ::




Custom Search