Graphics Programs Reference
In-Depth Information
Figure 4-1 . Rendering line primitives
Inside the initShapes method, initialize the vertex array lineVFA with vertices
(four unique vertices) representing a rectangle. After storing this vertex array as a
FloatBuffer , create the index array to access the vertices in lineVFA . Each
line primitive requires two vertices; so, to create a wireframe rectangle from line
primitives, use four sets of two vertices. Depending on the vertices you used inside
lineVFA , you can create the index array containing eight indices, as shown in List-
ing 4-5 . _lineISB is the buffer to store index array as a ShortBuffer . It is de-
clared as a member variable.
Listing 4-5. GL LINE ELEMENTS/src/com/apress/android/gllineelements/
GLES20Renderer.java
private void initShapes() {
float lineVFA[] = {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 lineVBB =
ByteBuffer.allocateDirect(lineVFA.length * 4);
lineVBB.order(ByteOrder.nativeOrder());
_lineVFB = lineVBB.asFloatBuffer();
_lineVFB.put(lineVFA);
_lineVFB.position(0);
short lineISA[] = {0,1, 1,2, 2,3, 3,0}; // 1,2 & 3
 
 
 
Search WWH ::




Custom Search