Small man (Bill man) Personal Original, welcome to reprint, reprint please indicate the address, small man (Bill man) column address http://blog.csdn.net/bill_man
1. OpenGL ES
OpenGL ES (OpenGL for Embedded System) is a subset of OpenGL designed for embedded devices. It also incorporates some extended functions to reduce power consumption for mobile devices.
2. Polygon and triangle
In 3D models, the basic unit is vertices. vertices form multiple edges and polygon form the 3D world. In OpenGL ES, performance-based polygon can only be formed by triangles. For example, a cube has six sides, and each side can be split into two triangles, which are 12 triangles in total.
OpenGL ES uses a three-dimensional Cartesian coordinate system. X, Y, zcoordinate values and vertex arrays of vertices used or part of objects constructed in the scenario are given.
3. Draw a triangle
The entire framework is first started through the portal activity, then a glsurfaceview is started through the activity, and a Renderer is enabled in glsurfaceview. The specific method is as follows:
Myrenderer = new scenerenderer (); // create a scene Renderer
This. setrenderer (myrenderer); // sets the Renderer
This. setrendermode (glsurfaceview. rendermode_continuously); // set the rendering mode to active rendering.
The class of this Renderer is implemented by ourselves. inherited from glsurfaceview and Renderer, we can call our own method in the ondrawframe method of rewriting.
Data Cache parameters are required in the descriptive parameters. The construction method of this parameter is as follows:
Allocate memory first
Bytebuffer vBB = bytebuffer. allocatedirect (vertices. length * 4 );
Because the vertex parameters are integer, the length of the vertices array is multiplied by 4 (vertices is the vertex integer vertex array) relative to the byte)
Then set the byte buffer byte sequence to the byte sequence of the local platform.
VBB. Order (byteorder. nativeorder ());
Then it can be converted to the int type buffer, placed into the coordinate data, set the initial position, etc.
Myvertexbuffer = vBB. asintbuffer ();
Myvertexbuffer. Put (vertices );
Myvertexbuffer. Position (0 );
Next, let's go back to the topic of triangle plotting. We can do this in four steps.
First, enable vertex array and color array for some initialization content.
Gl. glableclientstate (gl10.gl _ vertex_array); // enables the vertex coordinate array.
Gl. glableclientstate (gl10.gl _ color_array); // enables the vertex color array.
Specify the vertex coordinate data for the paint brush.
Gl. glvertexpointer (3, gl10.gl _ fixed, 0, myvertexbuffer );
The first parameter is the number of vertex coordinates, the second parameter is set to the integer coordinate, the third parameter is the interval between vertex coordinates, and the last parameter is the data cache parameter we first defined.
Then specify the color and index data for the paint brush respectively.
Gl. glcolorpointer (4, gl10.gl _ fixed, 0, mycolorbuffer );
Gl. gldrawelements (gl10.gl _ triangles, icount, gl10.gl _ unsigned_byte, myindexbuffer );
GL. the parameters of glcolorpointer are the same as those of glvertexpointer and gldrawelements. The first parameter is the fill type, which is triangle fill, the second parameter is the number of vertices, and the third parameter is the data cache class, here is the byte type, and the last parameter is the data cache parameter.
Now, we can basically build an OpenGL ES application.
Refer to the detailed explanation and typical cases of Android 3D Game Development Technology. If there are any errors, I hope you can correct them more.
Next, write the drawing method.