Intbuffer. Wrap (New int [] {...})
In android2.3, you cannot use intbuffer. Wrap to initialize the intbuffer object (floatbuffer is also the same) as in earlier versions. Otherwise, the system will throw an exception. You should directly use the allocatedirect method to allocate space for the buffer, and then use the bytebuffer. Put method to prevent raw data from being contained in the buffer.
E.g.
Bytebuffer vBB = bytebuffer. allocatedirect (Verts * 3*4 );
VBB. Order (byteorder. nativeorder ());
Floatbuffer mfvertexbuffer = vBB. asfloatbuffer ();
Mfvertexbuffer. Put (coords [I * 3 + J] * 2.0f );
Glfrontface
Function prototype
Void glfrontface (glenum mode );
The role is to control how the front of a polygon is determined. By default, the mode is gl_ccw.
The value of mode is:
Gl_ccw indicates that the vertex sequence of the projection Polygon on the window coordinate is clockwise and the surface is positive.
Gl_cw indicates that the face in clockwise direction of the vertex is positive.
The vertex direction is also called surround.
Glvertexpointer
The function glvertexpointer is used to associate an array with the vertex of a graph.
Parameter description:
Void glvertexpointer (glint size, glenum type, glsizei stride, const glvoid * pointer)
Glint is int type
Glenum is of the unsigned int type.
Glsizei is int type
Glvoid is void type
Size indicates how many pieces of data in the array will be used as the vertex data for each graph vertex after an array is bound.
Type specifies the type used to call the array data. Generally, the type of the defined array is one to one.
Stride specifies the bytes that each vertex should move from the array. Generally, the system automatically recognizes the write 0 statement. The recognition method is size * sizeof (the type is returned when the array is defined)
The address of the array to bind to pointer.
Gltexcoordpointer
Gltexcoordpointer (INT size, int type, int stride, buffer pointer); sets the vertex array as the texture coordinate cache.
Among them: Size: the number of texture vertex coordinates; // size: Number of coordinates per vertex;
Type: the data type of texture coordinates. Short, Int, float, and double can all be used;
Stride: the width of the bitmap. It can be understood as the number of bytes between two adjacent textures. Generally, it is 0, because other messages are not added to the texture. // Stride: Offset between 2 consecutive vertices;
Pointer: an array of texture coordinates. It specifies which corner of the texture is mapped to the I point (I <count) drawn, and the four corners are respectively () (upper left corner), () (upper right corner), () (lower right corner), () (lower left corner. For example
Intbuffer texcoords = intbuffer. Wrap (New int [] {
0, 1, 1, 1, 0, 0,
});
Gl. gltexcoordpointer (2, gl10.gl _ fixed, 0, texcoords );
Note: pointer uses the vertex array as the reference, rather than the index drawing as the reference! For example
Gl. glvertexpointer (3, gl10.gl _ fixed, 0, vertices );
Gl. gltexcoordpointer (2, gl10.gl _ fixed, 0, texcoords );
Gl. gldrawelements (gl10.gl _ triangle_strip, 4, gl10.gl _ unsigned_byte, indices );
Pointer takes the order of vertices as a reference, rather than the order specified by indices.
Gldrawelements
Usage of gldrawelements
Gldrawelements is an OpenGL primitive drawing function that obtains the Data Rendering elements from the array.
Function prototype:
Void gldrawelements (glenum mode, glsizei count,
Glenum type, const glvoid * indices );
Where:
Mode specifies the type of the graphic element. It should be one of the following values: gl_points, gl_line_strip, gl_line_loop, gl_lines, distance, distance, gl_triangles, gl_quad_strip, gl_quads, and gl_polygon.
Count represents the number of elements to be drawn multiplied by the number of vertices of an element.
Type is the index value type and can only be one of the following values: gl_unsigned_byte, gl_unsigned_short, or gl_unsigned_int.
Indices: pointer to the index storage location.
Glcullface:Specifies the polygon surface of the picking operation.
C language description
Void glcullface (glenum mode );
Parameters
Mode specifies which side of the polygon should be excluded, either gl_front or gl_back.
Description
This function allows you to disable illumination, shadow, and color calculation and operations on the front or back of a polygon to eliminate unnecessary rendering calculations, regardless of how the object is rotated or transformed, will not see the back of the polygon. You can use the gl_cull_face parameter to call the glable and gldisable parameters to enable or disable removal.
Http://www.cnblogs.com/yujunyong/archive/2011/04/17/2018776.html
Glloadidentity ()
Move the origin of the current user coordinate system to the center of the screen: similar to a reset operation
1. X axis from left to right, Y axis from bottom to top, and Z axis from inside to outside.
2. The coordinates of the OpenGL screen center are 0.0f points on the X and Y axes.
3. The coordinate value on the left of the center is a negative value, and the right is a positive value.
Moving to the top of the screen is positive, and moving to the bottom of the screen is negative.
Moving to the depth of the screen is a negative value, and moving out of the screen is a positive value.
Gltranslatef (x, y, z)
Move along the X, Y, and Z axes.
Note that in gltranslatef (x, y, z), when you move, you do not move relative to the center of the screen, but relative to the current screen position. The function is to translate the origin of the Point coordinate to A (x, y, z) vector based on the current origin.
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////
Glloadidentity ();
Gltranslatef (-1.5f, 0.0f,-6.0f );
Glbegin (gl_triangles );
Glvertex3f (0.0f, 0.0f, 0.0f );
Glvertex3f (1.0f, 0.0f, 0.0f );
Glvertex3f (0.0f, 1.0f, 0.0f );
Glend ();
Glloadidentity ();
Gltranslatef (0.0f, 0.0f,-6.0f );
Glbegin (gl_triangles );
Glvertex3f (0.0f, 0.0f, 0.0f );
Glvertex3f (1.0f, 0.0f, 0.0f );
Glvertex3f (0.0f, 1.0f, 0.0f );
Glend ();
//////////////////////////////////////// //////////////////////////////////////// /////
The program running result is as follows:
The triangle on the left is drawn in the first step. We can see that the coordinate system drawn by the triangle is actually based on (-1.5f, 0.0f,-6.0f.
When the second triangle is drawn, the origin is located in the center of the screen Because glloadidentity () is used to re-return the origin to the center of the screen.
Glrotatef (angle, x, y, z)
Similar to gltranslatef (x, y, z), glrotatef (angle, x, y, z) also operates the coordinate system.
The rotation axis goes through the origin. The orientation is (x, y, z), the rotation angle is angle, and the orientation meets the right-hand rule.
//////////////////////////////////////// ////////////////////////
Glloadidentity ();
Gltranslatef (0.0f, 0.0f,-6.0f );
Glbegin (gl_triangles );
Glvertex3f (0.0f, 0.0f, 0.0f );
Glvertex3f (1.0f, 0.0f, 0.0f );
Glvertex3f (0.0f, 1.0f, 0.0f );
Glend ();
//////////////////////////////////////// ////////////////////////
In the case of not rotating:
//////////////////////////////////////// ////////////////////////
Glloadidentity ();
Glrotatef (45, 0.0f, 0.0f, 1.0f );
Gltranslatef (0.0f, 0.0f,-6.0f );
Glbegin (gl_triangles );
Glvertex3f (0.0f, 0.0f, 0.0f );
Glvertex3f (1.0f, 0.0f, 0.0f );
Glvertex3f (0.0f, 1.0f, 0.0f );
Glend ();
//////////////////////////////////////// ////////////////////////
The positive rotation around the Z axis is 45 degrees, because the positive direction of the Z axis is directed to the outside of the screen from the screen, and the Right Hand determines that the direction is clockwise.
Since the right vertex is the origin point, it is rotated around the right corner counterclockwise.
How does a program execute the rotation and translation functions? Translation only: //////////////////////////////////////// /// // glloadidentity (); // reset the current modelview Matrix
Gltranslatef (0.0f, 0.0f,-6.0f );
Glbegin (gl_quads );
Glvertex3f (-0.01f,-0.01f, 0.0f );
Glvertex3f (0.01f,-0.01f, 0.0f );
Glvertex3f (0.01f, 0.01f, 0.0f );
Glvertex3f (-0.01f, 0.01f, 0.0f );
Glend ();
Glloadidentity ();
// Glrotatef (45.0f, 0.0f, 0.0f, 1.0f );
Gltranslatef (1.0f, 0.0f,-6.0f );
Glbegin (gl_triangles );
Glvertex3f (0.0f, 0.0f, 0.0f );
Glvertex3f (1.0f, 0.0f, 0.0f );
Glvertex3f (0.0f, 1.0f, 0.0f );
Glend (); //////////////////////////////////////// //// // The condition of rotation is added: /// // glloadidentity (); // reset the current modelview Matrix
Gltranslatef (0.0f, 0.0f,-6.0f );
Glbegin (gl_quads );
Glvertex3f (-0.01f,-0.01f, 0.0f );
Glvertex3f (0.01f,-0.01f, 0.0f );
Glvertex3f (0.01f, 0.01f, 0.0f );
Glvertex3f (-0.01f, 0.01f, 0.0f );
Glend ();
Glloadidentity ();
Glrotatef (45.0f, 0.0f, 0.0f, 1.0f );
Gltranslatef (1.0f, 0.0f,-6.0f );
Glbegin (gl_triangles );
Glvertex3f (0.0f, 0.0f, 0.0f );
Glvertex3f (1.0f, 0.0f, 0.0f );
Glvertex3f (0.0f, 1.0f, 0.0f );
Glend (); //// // If the rotation and the sequence of the statements are in the same what will happen if I change the result? //// // Glloadidentity (); // reset the current modelview Matrix
Gltranslatef (0.0f, 0.0f,-6.0f );
Glbegin (gl_quads );
Glvertex3f (-0.01f,-0.01f, 0.0f );
Glvertex3f (0.01f,-0.01f, 0.0f );
Glvertex3f (0.01f, 0.01f, 0.0f );
Glvertex3f (-0.01f, 0.01f, 0.0f );
Glend ();
Glloadidentity ();
Gltranslatef (1.0f, 0.0f,-6.0f );
Glrotatef (45.0f, 0.0f, 0.0f, 1.0f );
Glbegin (gl_triangles );
Glvertex3f (0.0f, 0.0f, 0.0f );
Glvertex3f (1.0f, 0.0f, 0.0f );
Glvertex3f (0.0f, 1.0f, 0.0f );
Glend (); // The three examples can be seen, the execution sequence of all statements that perform operations such as pan rotation on the image is from bottom to top. In addition, the center of the rotation Statement (0.0f, 0.0f, 0.0f) is known.
//////////////////////////////////////// ////////////////////////
Glloadidentity ();
Glrotatef (45, 0.0f, 0.0f, 1.0f );
Glloadidentity ();
Gltranslatef (0.0f, 0.0f,-6.0f );
Glbegin (gl_triangles );
Glvertex3f (0.0f, 0.0f, 0.0f );
Glvertex3f (1.0f, 0.0f, 0.0f );
Glvertex3f (0.0f, 1.0f, 0.0f );
Glend ();
//////////////////////////////////////// ////////////////////////
After rotation, a reset command is added, and the image will not be rotated.