Graphics Programs Reference
In-Depth Information
GLES20.glVertexAttribPointer(_pointAVertexLocation, 3,
GLES20.GL_FLOAT, false, 12, _pointVFB);
GLES20.glEnableVertexAttribArray(_pointAVertexLocation);
For data containing floating-point values, the type argument is
GLES20.GL_FLOAT . We must use this type for position, as well as for color data.
We do not want to normalize the vertex data, so, we set the boolean argument to
false . We use the stride argument if storing various types of per-vertex data
inside the same float array. For all cases in which we store a single type of ver-
tex data, such as vertex positions, inside a float array, we set stride as '0' or
size * the size of type argument. The indx and ptr arguments are for attrib-
ute location and buffer ( FloatBuffer _pointVFB ), respectively. If you look
closely at Listings 3-18 and 3-19, you will see that the attribute variable inside the
vertex shader code is of type vec4 , whereas the size argument in glVertexAt-
tribPointer is '3.' Well, the vertex shader can understand what we are doing
here; since we are rendering a vertex, it appends the extra component to make the
rendering possible. After calling the function glVertexAttribPointer , we
must also activate the corresponding attribute location, by calling glEnableVer-
texAttribArray , which takes the location of attribute variable as an argument.
Note While glVertexAttribPointer tells OpenGL about
the format (and source) of our vertex array data, glEnableVer-
texAttribArray activates the given attribute location, so that,
finally, OpenGL can pull this vertex data.
Listing 3-20. GLPOINTADVANCED/src/com/apress/android/glpointadvanced/
GLES20Renderer.java
public void onDrawFrame(GL10 gl) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT |
GLES20.GL_DEPTH_BUFFER_BIT);
GLES20.glUseProgram(_pointProgram);
GLES20.glVertexAttribPointer(_pointAVertexLocation,
3, GLES20.GL_FLOAT, false, 12, _pointVFB);
GLES20.glEnableVertexAttribArray(_pointAVertexLocation);
 
Search WWH ::




Custom Search