Game Development Reference
In-Depth Information
In OpenGL ES, we have to use a vertex array to define a group of vertices. So, you will:
1.
Define the (x, y, z) location of the vertices in a Java array.
2.
Allocate the vertex-array buffer, and transfer the data into the buffer.
To render from the vertex-array, you need to enable the client-state vertex-array, which is
done in gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); and then render the triangle in
the draw() method by doing the following:
1. Enable vertex-array client states:
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
2. Define the location of the buffers: gl.glVertexPointer
(3, GL10.GL_FLOAT, 0, vertexBuffer)
3. Render the primitives using glDrawElements() , using the index array
to reference the vertex and color arrays. gl.glDrawElements
(GL10.GL_TRIANGLES, numIndices, GL10.GL_UNSIGNED_BYTE,
indexBuffer)
Now you can run the project and see the result in Figure 3-2 .
Figure 3-2. Triangle OpenGL sample
 
Search WWH ::




Custom Search