Graphics Programs Reference
In-Depth Information
ponents of vectors is using the subscript “[ ]” operator and the indexing is zero-based,
so xyz[0] corresponds to the first component of this vector. As shown in Listing
3-9 , components of the xyz vector initialize the variable named “position,” which is
of type vec4 . The last component of “position” is set to '1', and, finally, its value is
assigned to the gl_Position variable.
Listing 3-10 demonstrates the use of component names . Depending on the number
of components that make up a given vector, each component can be accessed through
the component names {x, y, z, w}, {r, g, b, a}, or {s, t, r, q}. To access the in-
dividual components, first use the “.” operator with the vector name, followed by
the component name. However, please note that we cannot mix the component
naming conventions when accessing a vector; only one convention is used at a
time— vec4(xyz.x, xyz.y, xyz.z, 1) .
Listing
3-10. GL
POINT
BASIC/src/com/apress/android/glpointbasic/
GLES20Renderer.java
private final String _pointVertexShaderCode =
"void main() {"
+ " gl_PointSize = 15.0;"
+ ""
+ " // declare & initialize vec3 vector \n"
+ " vec3 xyz = vec3(0.0,0.0,0.0);"
+ ""
+ " // declare & initialize vec4 vector \n"
+ " vec4 position = vec4(xyz.x,xyz.y,xyz.z,1);"
+ " gl_Position = position;"
+ "}";
Finally, in Listing 3-11 , you see another style of using a vector constructor. If we
pass a single scalar argument to a vector constructor, its value is used to set all values
of the vector. So, using vec3(0.0) produces the same result as using vec3(0.0,
0.0, 0.0) . We can also pass a vector as an argument to a vector constructor. Since
the components of a vector are set from left to right (when using a vector construct-
or), vec4(vector3Name, 1) is identical to vec4(vector3Name.x, vec-
tor3Name.y, vector3Name.z, 1) .
Listing
3-11. GL
POINT
BASIC/src/com/apress/android/glpointbasic/
GLES20Renderer.java
 
 
 
 
 
 
Search WWH ::




Custom Search