Graphics Programs Reference
In-Depth Information
private final String _pointFragmentShaderCode =
"void main() {"
+ " vec4 fragColor = vec4(1.0);"
+ " // i.e. fragColor = vec4(1.0,1.0,1.0,1.0); \n"
+ " gl_FragColor = fragColor;"
+ "}";
Although everything is fine in Listing 3-13 , this code will not produce the intended
result shown in Figure 3-8 , because there is an important difference between a vertex
and fragment shader. To be specific, you will get a blank screen if you replace the
fragment shader code in the Renderer class in GL POINT BASIC application with
Listing 3-13 .
In GLSL , variables of type int or float must specify precision qualifiers. Preci-
sion qualifiers allow us to specify the precision with which computations for a shader
variable are performed. Variables can be declared to have low, medium, or high pre-
cision, which is specified using keywords lowp , mediump , or highp , respectively.
The default precision qualifier is specified at the top of a vertex or fragment shader
( Listing 3-14 ):
precision mediump float;
precision mediump int;
3-14. GL
private final String _pointFragmentShaderCode =
+ "precision highp float;"
+ "#else \n"
+ "precision mediump float;"
+ "#endif \n"
+ "void main() {"
+ " vec4 fragColor = vec4(1.0);"
+ " gl_FragColor = fragColor;"
+ "}";
Search WWH ::

Custom Search