Analysis of polygon function on drawing plane developed by Android

This paper describes the polygon drawing function on the plane developed by Android. Share with you for your reference, as follows:

The 3D graphics in the computer are actually composed of many planes. The so-called "drawing 3D" graphics are actually formed through multiple plane graphics. The steps of calling gl10 graphics to draw 2D graphics are as follows:

i. Call the glenableclientstate of gl10 (gl10. Gl_vertex_array); Method to enable vertex coordinate arrays.

II. Call the glenableclientstate of gl10 (gl10. Gl_color_array); Method to enable vertex color arrays.

III. call glvertex (int size, int type, int stripe, buffer pointer) of gl10; Method to set the position data of vertices. In this method, the pointer parameter is used to specify the vertex coordinate value, but the three-dimensional array is not used to specify the X, y and Z coordinates of each vertex. The pointer is still a one-dimensional array in the format of (x1, Y1, Z1, X2, Y2, Z2, X3, Y3, Z3... Xn, YN, Zn); In other words, the array will contain 3N values. Every three values will specify the type of X, y and Z coordinate values of a vertex. If the vertex coordinate value is of float type, it will be specified as gl10.gl_ FLOAT; If the vertex coordinate value is an integer, it is specified as gl10.gl_ FIXED。

IV. call glcolorpointer (int size, buffer pointer) method of gl10 to set color data of vertices. In this method, the pointer parameter is used to specify the color value of vertices. The pointer is still a one-dimensional array in the format of (R1, G1, B1, A1, A2, Z3, A3... Xn, Zn, an); That is, the array will contain 4N values. Every four values specify the color value of red, green and blue transparency of a vertex. The first parameter size specifies how many elements specify a vertex position. The size parameter is usually 4,; The type parameter specifies the type of vertex coordinate value. If the vertex coordinate value is of float type, it is specified as gl10.gl_ FLOAT; If the vertex coordinate value is an integer, it is specified as gl10.gl_ FIXED。

v. Call the gldrawarrays (int mode, int first, int count) method of gl10 to draw the plane. The first parameter of this method is used to specify the drawing shape type, the second parameter specifies which vertex to draw from, and the third parameter specifies the total number of points to draw.

When VI. is finished, the glFinish () method of GL10 is used to end the rendering. And call gldisableclientstate (int) method to disable vertex coordinate data and vertex color data.

After mastering the above steps, next draw several simple graphics through the example program.

The above program uses gl10 to draw the key code of graphics: load vertex position data; Load vertex color data; Call gldrawarrays of gl10 to draw.

Define a glsurfaceview in the activity and use the renderer above to draw. The procedure is as follows:

You may wonder why the second and third figures only define four coordinate points in a slightly different order. Why are the graphics so different? The mode of drawing should be specified for the first parameter of the gldrawarrays method, gl10.gl_ Triangles is to draw triangles, gl10.gl_ TRIANGLE_ Strip draws polygons with multiple triangles.

For the second graph, when the gldrawarrays (int mode, int first, int count) method is called, if gl10.gl is specified as the first parameter_ TRIANGLE_ When strip, the system always starts from the first vertex and draws a triangle every 3 vertices.

More readers interested in Android related content can view the special topics of this site: summary of Android graphics and image processing skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solving methods, summary of Android basic component usage, summary of Android view skills, summary of Android layout skills, and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>