Graphics Programs Reference
In-Depth Information
OpenGL surface. We usually create shaders directly inside this renderer
( GLES20Renderer class) as literal strings ( Listing 3-8 ).
Listing
3-8. GL
POINT
BASIC/src/com/apress/android/glpointbasic/
GLES20Renderer.java
private final String _pointVertexShaderCode =
"void main() {"
+ " gl_PointSize = 15.0;"
+ " gl_Position = vec4(0.0,0.0,0.0,1);"
+ "}";
The syntax of shaders is similar to that of the C programming language. If you can
read and understand a simple C program, you will quickly grasp the basic structure
of shaders .
GLSLshaders have a single entry point, called the main function, as shown in Listing
3-8 . Additionally, they have built-in variables to provide useful information to the
rendering pipeline. The point vertex shader ( _pointVertexShaderCode ) in
Listing 3-8 makes use of two important built-in variables— gl_PointSize and
gl_Position .
As the name suggests, gl_PointSize specifies the size of a “point” in pixels.
This built-in variable can only be used with a specific type of geometric object in ES
2.0—a point sprite .
In ES 2.0, any object (for example, triangle, square, and cube) rendered on the
OpenGL surface can only be expressed as a combination of any one of the following
fundamental geometric objects (known as primitives ):
Point sprite
Line
Triangle
We describe a primitive by a set of vertices (a single vertex in case of one point sprite
, two vertices for a line , and three vertices for a triangle ) and optional data for colors
and textures. The vertex shader shown in Listing 3-8 is for rendering a point sprite
primitive; this primitive is a square shaped point, and, as already stated, we specify
its size using the gl_PointSize built-in.
 
 
 
Search WWH ::




Custom Search