Create a DrawLine Activity that defines four vertices:
float vertexarray[] =-0.8f,-0.4f1.732f0.0f- 0.4f0.4f1.732f0.0f0.0f,-0.4f1.732f 0.0f0.4f0.4f1.732f0.0f,};
Draw the line in three modes Gl_lines,gl_line_strip,gl_line_loop, respectively:
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_lines,0,4); Break; Case 3: Case 4: Case 5: gl.glcolor4f (0.0f,1.0f,0.0f,1.0f); Gl.gldrawarrays (Gl10.gl_line_strip,0,4); Break; Case 6: Case 7: Case 8: Case 9: gl.glcolor4f (0.0f,0.0f,1.0f,1.0f); Gl.gldrawarrays (Gl10.gl_line_loop,0,4); 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, lines, Line_strip,line_loop.
Android OpenGL ES (ix) Draw segment line Segment.