Graphics Programs Reference
In-Depth Information
After setting the position of the FloatBuffer using
_pointVFB.position(0) , create a short array to store (zero-based) index
positions of the vertices in array pointVFA , as shown in Listing 4-3 . If you want to
render all the vertices from this vertex array, store all the indices {0, 1, 2, 3} in the
short array (say pointISA ). Then, store this index array in a ShortBuffer , as
shown in Listing 4-3 . Here, _pointISB is a field (that is, a member variable) of
type ShortBuffer .
Finally, in the onDrawFrame method, remove the call to glDrawArrays , and re-
place it with the line of code in Listing 4-4 .
Listing 4-4. GL POINT ELEMENTS/src/com/apress/android/glpointelements/
GLES20Renderer.java
GLES20.glDrawElements(GLES20.GL_POINTS, 4,
GLES20.GL_UNSIGNED_SHORT, _pointISB);
glDrawElements takes four arguments. The first argument is the mode (for the
type of primitive), the second argument is the count of indices stored in the in-
dex array (if in place of '4' you specify '3', the point sprite in the fourth quad-
rant won't be rendered), the third argument is data type of index array, and the last
argument is the index array buffer or the address of index array ( Chapter 5 dis-
cusses the address argument). In Listing 4-4 , the arguments are GL_POINTS , 4 ,
GL_UNSIGNED_SHORT , and ShortBuffer _pointISB , respectively.
To see the Renderer class with all of these changes, import the archive file
Chapter4/glpointelements.zip . This loads the GL POINT ELEMENTS
application into your workspace. Please note that the shader _pointFrag-
mentShaderCode still works if you remove the precision settings outside the
main function.
Drawing Line and Triangle Primitives
Here, I describe how to create a wireframe rectangle, as shown in Figure 4-1 ,
with the help of line primitives and glDrawElements . Import the archive file
Chapter3/glline.zip into your workspace, and start making changes to the
Renderer class in the loaded application GL LINE .
 
 
 
Search WWH ::




Custom Search