Graphics Programs Reference
In-Depth Information
Note Apart from creating shaders as string literals, we can also cre-
ate them in separate files. However, since we create shaders directly
inside the GLES20Renderer class (as string literals), we must ap-
pend some lines of shaders with “\n.” We only do this for lines that
contain single line comments or preprocessor directives (yes, GLSL
supports comments and preprocessor directives).
For most ES 2.0 applications in the source code, you will observe
that all lines of shaders are appended with “\n.” This has been done
for readability purposes only, but you should understand which lines
necessarily require “\n.”
In Listing 3-9 , instead of directly assigning the value '15.0' to gl_PointSize
variable, another variable pointSize is declared and initialized. Its value is as-
signed to gl_PointSize variable using gl_PointSize = pointSize .
3-9. GL
private final String _pointVertexShaderCode =
"void main() {"
+ " // declare & initialize float scalar \n"
+ " float pointSize = 15.0;"
+ " gl_PointSize = pointSize;"
+ ""
+ " // using vec3 constructor \n"
+ " vec3 xyz;"
+ " xyz = vec3(0.0,0.0,0.0);"
+ ""
+ " // using vec4 constructor \n"
+ " vec4 position;"
+ " position = vec4(xyz[0],xyz[1],xyz[2],1);"
+ " gl_Position = position;"
+ "}";
A three-component vector, named “xyz,” is first declared, and then it is initialized
using vec3 constructor vec3(0.0, 0.0, 0.0) . One way to access the com-
Search WWH ::

Custom Search