The triangle is a polygon supported by OpenGL ES and also creates a drawtriangle Activity that defines 6 vertices using three different patterns to draw the triangle:
floatVertexarray[] = { -0.8f, -0.4f*1.732f,0.0f, 0.0f, -0.4f*1.732f,0.0f, -0.4f,0.4f*1.732f,0.0f, 0.0f, -0.0f*1.732f,0.0f, 0.8f, -0.0f*1.732f,0.0f, 0.4f,0.4f*1.732f,0.0f,};
This example draws
Public voidDrawscene (GL10 gl) {super. Drawscene (GL); Bytebuffer VBB= Bytebuffer.allocatedirect (vertexarray.length*4); Vbb.order (Byteorder.nativeorder ()); Floatbuffer Vertex=Vbb.asfloatbuffer (); Vertex.put (Vertexarray); Vertex.position (0); Gl.glloadidentity (); Gl.gltranslatef (0,0, -4); Gl.glenableclientstate (Gl10.gl_vertex_array); Gl.glvertexpointer (3, Gl10.gl_float,0, vertex); Index++; index%=Ten; Switch(index) { Case 0: Case 1: Case 2: gl.glcolor4f (1.0f,0.0f,0.0f,1.0f); Gl.gldrawarrays (Gl10.gl_triangles,0,6); Break; Case 3: Case 4: Case 5: gl.glcolor4f (0.0f,1.0f,0.0f,1.0f); Gl.gldrawarrays (Gl10.gl_triangle_strip,0,6); Break; Case 6: Case 7: Case 8: Case 9: gl.glcolor4f (0.0f,0.0f,1.0f,1.0f); Gl.gldrawarrays (Gl10.gl_triangle_fan,0,6); Break; } Gl.gldisableclientstate (Gl10.gl_vertex_array); }
The purpose of this index is to delay the display (a better practice is to use a fixed interval). As I said before, there are two kinds of glsurfaceview rendering modes, one is the continuous update screen, the other is On-demand, only in the call Requestrender () on the update screen. The default is rendermode_continuously to refresh the screen continuously.
Opengldemos is using the default rendermode_continuously continuous refresh screen, so the drawscene of activity will continue to execute. In this example, the screen order is shown in red, green, blue, triangles, Triangle_strip,triangle_fan.
Android OpenGL ES (10) draws a triangular triangle.