Graphics Programs Reference
In-Depth Information
ing glDrawElements , this array must contain unique vertices corresponding to
the corners of a rectangle.
Listing 4-7. GL RECTANGLE ELEMENTS/src/com/apress/android/glrect-
angleelements/GLES20Renderer.java
float rectangleVFA[] = {
0.2f,0.2f,0.0f, -0.2f,0.2f,0.0f, -0.2f,-0.2f,0.0f,
0.2f,-0.2f,0.0f
};
ByteBuffer rectangleVBB =
ByteBuffer.allocateDirect(rectangleVFA.length * 4);
rectangleVBB.order(ByteOrder.nativeOrder());
_rectangleVFB = rectangleVBB.asFloatBuffer();
_rectangleVFB.put(rectangleVFA);
_rectangleVFB.position(0);
short rectangleISA[] = {
0,1,2, // upper triangle
2,3,0 // lower triangle
};
ByteBuffer rectangleIBB =
ByteBuffer.allocateDirect(rectangleISA.length * 2);
rectangleIBB.order(ByteOrder.nativeOrder());
_rectangleISB = rectangleIBB.asShortBuffer();
_rectangleISB.put(rectangleISA);
_rectangleISB.position(0);
Now, create the index array with sets of indices corresponding to upper and lower tri-
angles ( short[] rectangleISA , Listing 4-7 ) . For example, if you used vertices
{A, B, C, D} in the first, second, third, and fourth quadrants, respectively, to rep-
resent rectangle, then, one of the possible combinations of indices that can be used
for rendering rectangle using glDrawElements with mode GL_TRIANGLES is
{0, 1, 2} and {2, 3, 0} .
 
Search WWH ::




Custom Search