Graphics Programs Reference
In-Depth Information
GLES20.GL_FRAGMENT_SHADER ). Then, the shader source code (vertex or frag-
ment shader code) is loaded to this object using glShaderSource function, which
is finally compiled using glCompileShader function and is then returned. Please
note that shader source code of each type (that is, vertex and fragment shader) needs
to be loaded to this shader-object before it can be used in an ES 2.0 program .
Inside the onSurfaceCreated or onSurfaceChanged method, we use these
compiled shaders by creating an ES 2.0 program using the glCreateProgram
function. Compiled shaders must be loaded to this program using glAt-
tachShader before they are finally linked as a unit ( Listing 3-16 ) .
Listing
3-16. GL
POINT
BASIC/src/com/apress/android/glpointbasic/
GLES20Renderer.java
int pointVertexShader =
loadShader(GLES20.GL_VERTEX_SHADER,
_pointVertexShaderCode);
int pointFragmentShader =
loadShader(GLES20.GL_FRAGMENT_SHADER,
_pointFragmentShaderCode);
_pointProgram = GLES20.glCreateProgram();
GLES20.glAttachShader(_pointProgram,
pointVertexShader);
GLES20.glAttachShader(_pointProgram,
pointFragmentShader);
GLES20.glLinkProgram(_pointProgram);
Attributes
Before we explain this application further, make few additions to the Renderer
class. Include the fields int _pointAVertexLocation and FloatBuffer
_pointVFB to this class. Then, create a new method initShapes() with type
void . Inside this method, add the lines of code from Listing 3-17 . Call
initShapes anywhere inside onSurfaceChanged method.
Listing 3-17. GLPOINTADVANCED/src/com/apress/android/glpointadvanced/
GLES20Renderer.java
 
 
 
 
 
Search WWH ::




Custom Search