Android Study Notes-3D-(02)-OpenGL ES APIs

Source: Internet
Author: User

 

Common OpenGL ES APIs:

 

Gl_triangle_strip: continuous triangle drawing

Gl_triangle_fan: triangular slice

 

 

 

 

Glclearcolor (0.f, 0.f, 0.f, 1.f); // set the background color of the mode window. The color is the rgba value.

 

Glviewport (0, 0, iscreenwidth, iscreenheight); // you can specify the size and position of the view. The view is the area where the image is finally displayed on the screen. The first two parameters are the position of the view, the latter two parameters are the width and length of the view.

 

Glmatrixmode (gl_projection); // you can specify the matrix mode as the projection matrix. Subsequent transformations affect the projection matrix. OpenGL is a state management mechanism. For example, after you set the current matrix to a projection matrix, any matrix transformation will affect the projection matrix before you call glmatrixmode () again.

 

Glfrustumf (-1.f, 1.f,-1.f, 1.f, 3.f, 1000.f); // This function creates a perspective projection matrix. The parameters define the visual object, which can be understood as a camera, the visible range of the eye. Just like a triangular pyramid, parameters 1, 3, 5, 2, 4, and 6 define the coordinates of the near-cut surface and the lower left and upper right (x, y, z) of the far-cut surface.

 

OpenGL projection has two modes: Perspective Projection, that is, creating a three-pyramid visual body through the above functions. In this mode, the three-dimensional model of viewing is nearly large and small. The other mode is orthogonal mode. The visual object is a parallel Al, and the distance from the camera does not affect the object size.

 

Glmatrixmode (gl_modelview); // you can specify the current matrix as the mode matrix.

 

Glvertexpointer (3, gl_byte, 0, vertices); // specifies where to access spatial coordinate data

 

OpenGL has a total of eight such functions that can access different coordinate data:

 

Glcolorpointer ();

 

Glindexpointer ();

 

Glnormalpointer ();

 

Gltexcoordpointer ();

 

Glshademodel (gl_flat); // sets the shadow mode to gl_flat. The default gl_smooth shadow mode has two types: gl_smooth and gl_flat, which have different effects in case of care.

 

Glclear (gl_color_buffer_bit); // clear the color Cache

 

Glloadidentity (); // sets the current matrix as a matrix of units. After the gl10.glloadidentity method is called, the current coordinate origin is actually moved to the center of the screen, which is the origin of the OpenGL coordinate system.

 

 

 

The positions and sizes in OpenGL are expressed in matrices. For example, glscanf () is used to zoom in or out. In fact, a matrix is used to multiply the current matrix, in order to make the transformation not affected by the current matrix, set the current matrix as the unit matrix.

 

Gltranslatex (0, 0,-100 <16); // move the coordinates to the negative direction of the Z axis by 100

 

Glcolor4f (1.f, 0.f, 0.f, 1.f); set the color to red.

 

/* Scale the geometry */

 

Glscalex (15 <16, 15 <16, 15 <16, 15 <16); // scale up an object by 15 times along XYZ

 

/* Draw the triangle */

 

Gldrawelements (gl_triangles, 1*3, gl_unsigned_byte, indices); // draw a graph. gl_triangles indicates that the graph to be drawn is a triangle. 3 indicates that there are three fixed points in total, gl_unsigned_byte indicates the Data Type stored by indices

 

A call to eglswapbuffers () can then be made.

 

Gltranslatef (glfloat X, glfloat y, glfloat Z)

Gltranslatex (glfixed X, glfixed y, glfixed Z) function: Pan along X, Y, and Z

 

Glscalef (glfloat X, glfloat y, glfloat Z)

Glscalex (glfixed X, glfixed y, glfixed Z) features: zooming in the X, Y, and Z axes, the parameters x, y, and z are the desired size.

 

Glrotatef (glfloat angle, glfloat X, glfloat y, glfloat Z)

Glrotatex (glfixed angle, glfixed X, glfixed y, glfixed Z) function: rotate along the X, Y, and Z axes. Angle indicates the angle to be rotated.

 

Glclear (glbitfield mask) function: you can clear the cache in three modes: gl_color_buffer_bit, gl_depth_buffer_bit, and gl_stencil_buffer_bit.

 

Glcleardepthf (glclampf depth) void glcleardepthx (glclampx depth) function: sets the depth cache. The parameters are from 0 to 1. Use glclear to clear the cache. Deep cache is used by OpenGL in 3D scenarios. Its sorting determines that the object is first painted. In this way, you will not draw a square behind a circle to a circle.

 

Glclearcolor (glclampf red, glclampf green, glclampf blue, glclampf alpha)

Glclearcolorx (glclampx red, glclampx green, glclampx blue, glclampx alpha)

Function: Clear the color cache with the specified color value (rgba)

 

Glcolorpointer (glint size, glenum type, glsizei stride, const glvoid * pointer) function: Specifies the color storage space. The size is 4 by default in OpenGL ES, indicating (rgba ); type is the type of pointer content, stride is the offset of data in Pointer memory, and pointer is the address of the first element.

 

Glenableclientstate (glenum array) function: Enable Array

Gldisableclientstate (glenum array) function: Disable Array

Array: gl_color_array,

Gl_matrix_index_array_oes,

Gl_normal_array,

Gl_point_size_array_array_oes,

Gl_texture_coord_array,

Gl_vertex_array,

Gl_weight_array_oes.

 

Gldrawelements (glenum mode, glsizei count, glenum type, const glvoid * indices) function: draws a graph based on the value specified by the parameter. Mode specifies the type to be drawn: gl_points, gl_line_strip, gl_lines, gl_triangle_strip, gl_triangle_fan, and gl_triangles; count specifies the number of entries to be drawn; Type specifies indices as the first address of the array.

 

Glflush (); send the commands in the GL command queue to the graphics card, clear the command queue, and return immediately after sending (the command may not be completed)

Glfinish () sends the commands in the GL command queue to the graphics card and clears the command queue. After the graphics card completes these commands, it returns (the painting command is completed)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.