Graphics Programs Reference
In-Depth Information
Figure 3-12 . Using varying in vertex shaders
To use a varying variable, it should be declared in a vertex and fragment shader
such that it has same type in both shaders. To understand this, import the archive file from the Chapter3 folder. This will load the GL VARYING ap-
plication into your workspace. If you browse through the contents of the Renderer
class, you will see right away that it is for rendering a line primitive.
First, notice the initShapes method inside the Renderer class. Apart from the
float array for vertex positions ( lineVFA ), it contains another array— lineCFA .
The first four elements in this array (0, 0, 1, 1) represent blue color, whereas
the last four elements (1, 1, 0, 1) represent yellow color. This per-vertex
color data is passed to the attribute variable aColor (recall that float array for
an attribute is passed as FloatBuffer ) using the ES 2.0 function glVertexAt-
tribPointer , as shown in Listing 3-21 .
Listing 3-21. GL VARYING/src/com/apress/android/glvarying/GLES20Render-
public void onDrawFrame(GL10 gl) {
GLES20.glVertexAttribPointer(_lineAVertexLocation, 3,
GLES20.GL_FLOAT, false, 0, _lineVFB);
Search WWH ::

Custom Search