Graphics Programs Reference
In-Depth Information
a binary format so the GPU can process it. There are three ES 2.0 func-
tions— glCreateShader , glShaderSource , and glCom-
pileShader —that we have to use every time we compile a vertex and a fragment
shader.
Once we have compiled the shaders for an object (recall that an object is a primitive
or a combination of the same type of primitives), we must create an ES 2.0 program
for it (not to be confused with the shader program ) that links the vertex and fragment
shader as a unit. Using this program object, we render primitives on the OpenGL
surface. To see these steps in action, import the archive file glpointbasic.zip
from the Chapter3 folder. This will load the GL POINT BASIC application into your
Eclipse workspace.
Using the loadShader Method
The Renderer class contains the good old methods ( onSurfaceCreated ,
onSurfaceChanged , and onDrawFrame ), using which we can easily organize
code for different purposes (which we previously discussed). There are two primary
changes in this class— shader programs and the loadShader method—and, from
this point forward, we use these in all ES 2.0 applications.
I already explained the use of shaders (to render a point sprite primitive, the Renderer
class contains both vertex and fragment shaders), so let's talk about the
loadShader method ( Listing 3-15 ).
Listing
3-15. GL
POINT
BASIC/src/com/apress/android/glpointbasic/
GLES20Renderer.java
private int loadShader(int type, String source) {
int shader = GLES20.glCreateShader(type);
GLES20.glShaderSource(shader, source);
GLES20.glCompileShader(shader);
return shader;
}
Inside this method, there are three ES 2.0 functions to help us with the compilation of
shaders. Using int shader = GLES20.glCreateShader(type) , shader-
object is created for a specific type of shader ( GLES20.GL_VERTEX_SHADER or
 
 
 
Search WWH ::




Custom Search