Graphics Programs Reference
In-Depth Information
Figure 5-5 . Using texture and color
By now you should understand that you can either create a color directly inside the
fragment shader or you can use an attribute variable in the vertex shader to receive
colors separately for each vertex and pass this per-vertex color (as a varying variable)
to the fragment shader. Listing 5-8 contains the vertex and fragment shader code re-
quired to set the fragment color as a combination of texture color and varying color.
Listing 5-8. GL TEXTURE COLOR/src/com/apress/android/gltexturecolor/
private final String _planeVertexShaderCode =
"attribute vec4 aPosition; \n"
+ "attribute vec2 aCoord; \n"
+ "attribute vec4 aColor; \n"
+ "varying vec2 vCoord; \n"
+ "varying vec4 vColor; \n"
+ "uniform mat4 uMVP; \n"
+ "void main() { \n"
+ " gl_Position = uMVP * aPosition; \n"
+ " vCoord = aCoord; \n"
+ " vColor = aColor; \n"
+ "} \n";
private final String _planeFragmentShaderCode =
Search WWH ::

Custom Search