Graphics Programs Reference
In-Depth Information
Using
glDrawArrays
, with
mode GL_TRIANGLES
, an easy way to render a
rectangle is by creating a
float
array for points that form a closed loop. When we
call
glDrawArrays
for such a collection of points, we need to pass the
count
ar-
for each of the upper and lower triangles.
Listing
3-23.
GL
RECTANGLE/src/com/apress/android/glrectangle/
GLES20Renderer.java
float rectangleVFA[] = {
0, 0, 0,
0, 0.5f, 0,
0.75f, 0.5f, 0, // upper triangle
0.75f, 0.5f, 0,
0.75f, 0, 0,
0, 0, 0, // lower triangle
};
You must make three changes to the
GL POINT ADVANCED
application to render a
rectangle as shown in
Figure 3-14
:
1. Remove the line “
gl_PointSize = 15.0; \n
” from the point
vertex shader code (
_pointVertexShaderCode
).
2. Replace the contents of array
pointVFA
(inside
initShapes
meth-
od) with the points given in
Listing 3-23
.
3. Modify the call to
GLES20.glDrawArrays
method as
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
.
Search WWH ::
Custom Search