Graphics Programs Reference
In-Depth Information
Note Recall that you can set a single color for the rendered object
by directly writing to the built-in shader vari-
able— gl_FragColor . To set white color for the rendered object,
write the vec4 - (1.0, 1.0, 1.0, 1) to the
gl_FragColor variable. Similarly, to set cyan color, write the
vec4 - (0.0, 1.0, 1.0, 1) .
To demonstrate this, import the application GL MASK ( Chapter5/glmask.zip )
into your Eclipse workspace. This application is almost identical to the GL
RECTANGLE application in the source code for Chapter 3 , except for the Renderer
class in GL MASK application, which renders two rectangles ( Figure 5-1 ) instead of
just one.
Listing 5-3 contains lines of code (from the GLMASK application) to set color masks
for two rectangles. Please note that, to avoid the first call to glColorMask affect-
ing the color masks set for the second rectangle, color masks for all components are
reset by calling glColorMask(true, true, true, true) .
Listing 5-3. GL MASK/src/com/apress/android/glmask/GLES20Renderer.java
GLES20.glUseProgram(_rectangleTwoProgram);
GLES20.glVertexAttribPointer(_rectangleTwoAVertexLocation,
3, GLES20.GL_FLOAT, false, 0, _rectangleTwoVFB);
GLES20.glEnableVertexAttribArray(_rectangleTwoAVertexLocation);
GLES20.glColorMask(false, true, false, true);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
GLES20.glColorMask(true, true, true, true);
GLES20.glUseProgram(_rectangleOneProgram);
GLES20.glVertexAttribPointer(_rectangleOneAVertexLocation,
3, GLES20.GL_FLOAT, false, 0, _rectangleOneVFB);
GLES20.glEnableVertexAttribArray(_rectangleOneAVertexLocation);
GLES20.glColorMask(true, false, false, true);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
GLES20.glColorMask(true, true, true, true); // reset
color masks for glDraw* calls ahead
 
 
 
Search WWH ::




Custom Search