Learn about Android OpenGLES2.0 (i) _android

Source: Internet
Author: User
Tags cos garbage collection reflection

What is OpenGL ES?

OpenGL (Full write open Graphics Library) refers to the definition of a cross programming language, Cross-platform programming interface specifications of the professional Graphics program interface. It is used in three-dimensional images (also two-dimensional), is a powerful, easy to invoke the underlying graphics library.

OpenGL has different implementations on different platforms, but it defines a professional program interface, different platforms are implemented in accordance with the interface, the idea is the same, the method name is consistent, so the use is basically consistent, just according to the different language environment slightly different. OpenGL this set of 3D graphics API from the 1992 release of the 1.0 version to the current 2014 release of the 4.5 version, on many platforms have a wide range of uses.

OpenGL ES (OpenGL for Embedded Systems) is a subset of the OpenGL three-dimensional graphics API designed for embedded devices such as mobile phones, PDAs, and game consoles.

OpenGL ES, in contrast to OpenGL, reduces the number of methods and data types that are not required, removes the unnecessary functionality, and limits the cost of the function, which is lighter than OpenGL. In the OpenGL ES World, there is no quadrilateral, polygon, no matter how complex graphics are composed of dots, lines and triangles, but also remove the glbegin/glend and other methods.

What can OpenGL es do?

OpenGL ES is a mobile phone, PDA and game host, such as embedded devices three-dimensional (two-dimensional also includes) graphics processing API, of course, is used in the embedded Device graphics processing, OpenGL es powerful rendering capabilities so that it becomes our embedded devices on the graphics processing excellent choice. The scenes we often use are:

    • Picture processing. such as picture tonal conversion, beauty and so on.
    • Camera preview effect processing. such as beauty camera, spoof camera and so on.
    • Video processing. Camera preview effect processing can be, this nature is nothing.
    • 3D Games. such as the Temple escape, urban racing and so on.

OpenGL es version and Android support

The current major version of OpenGL es is 1.0/1.1/2.0/3.0/3.1. The main scenarios for these editions are as follows:

OpenGL ES1.0 is based on OpenGL 1.3, and OpenGL ES1.1 is based on OpenGL 1.5. Android
1.0 and higher versions support this API specification. The OpenGL ES 1.x is for fixed hardware pipelines.
OpenGL ES2.0 is based on OpenGL 2.0 and is not compatible with OpenGL ES 1.x. The Android 2.2 (API 8) and the higher version support this API specification. OpenGL ES 2.x is for programmable hardware pipelines.
The technical features of OpenGL ES3.0 are almost entirely from OpenGL 3.x, backward-compatible OpenGL ES 2.x. The Android 4.3 (API 18) and higher versions support this API specification.
OpenGL ES3.1 can basically belong to OpenGL 4.x subset, backward-compatible OpenGL es3.0/2.0. The Android 5.0 (API 21) and the higher version support this API specification.

The advantages of OpenGL ES 2.0

Because OpenGL ES 3.x are backward-compatible OpenGL ES 2.0, plus the current mainstream Android phone is 4.4+, but there are still some Android2.3, Android4.0 "Classic machine." So learning OpenGL ES to select version 2.0 is a relatively optimal choice. Of course, although OpenGL ES 2.0 is not compatible with OpenGL ES 1.x, they have a lot in common in their use.
Compared to OpenGL es 1.x,opengl ES 2.0, it has made great changes, more flexible, more powerful, and more rendering efficiency and better performance. Of course, flexibility may make you feel much more complex to use than OpenGL ES 1.x.
The "vertex shader" in OpenGL ES 2.0 replaces the "Transform and lighting phase" in OpenGL ES 1.x, and the slice shader replaces the phases of "texture color and environment summation", "Fog", "alpha test", and so on. So that the original OpenGL ES 1.x fixed phase requires the user to develop their own shader processing, although to a certain extent, increased the complexity of the code, but the flexibility is greatly increased, but also able to deal with OpenGL ES 1.x difficult to complete processing tasks.
The following figure is a programmable rendering pipeline for OpenGL ES 1.x and OpenGL ES 2.0:

Basic Concepts in OpenGL ES 2.0

Learning OpenGL ES 2.0 needs to know some of the concepts and knowledge associated with OpenGL ES 2.0.
In the previous paragraph, we mentioned two important things about OpenGL ES 2.0 relative to 1.x--vertex shader and chip shader.

Vertex shader

A shader (Shader) is a small program that runs on a GPU. As you can see from the name, you can handle vertices by handling them. This program is written using the OpenGL ES SL language. It is a simple program that describes the characteristics of vertices or pixels.
For each vertex that is sent to the GPU, a vertex shader is executed once. The function is to transform the three-dimensional coordinates of each vertex in the virtual space into two-dimensional coordinates that can be displayed on the screen and with depth information for z-buffer. The properties that a vertex shader can manipulate are: position, color, texture coordinates, but cannot create a new vertex.

The input and output model for the vertex shader is as follows:

Slice-Element shader

The slice-element shader calculates the color and other properties of each pixel. It calculates the pixel color and outputs it by applying illumination values, bump maps, shadows, specular highlights, and translucent processing. It can also change the depth of the pixel (z-buffering) or output multiple colors in a state where multiple render targets are activated. A chip shader cannot produce complex effects because it operates on only one pixel without knowing the geometric shape of the scene.
The input and output model of the chip shader is as follows:

Shader language

The shader language (shading Language) is an advanced graphical programming language that is only suitable for GPU programming and derives from a wide range of C languages. The development of the vertex shader and the chip shader needs to be developed using the shader language. It is process-oriented rather than object-oriented.
The variables in the shader language, and the syntax will be mentioned later in the use process. To learn the shader language for your system, check out other related blogs and books.

Coordinates

OpenGL es is right-handed, select the center of the screen as the origin, from the origin to the screen edge of the default length of 1, that is, by default, from the origin to (1,0,0) distance and to (0,1,0) distance on the screen display is not the same. That is, to the right x positive axis direction, to the left x negative axis direction, up to the y-axis positive axis direction, downward to the Y axis negative axis direction, the screen surface vertically upward to the z-axis positive axis direction, vertical downward to the z axis negative axis direction.

Drawing of graphs

In the world mentioned in the OpenGL ES2.0, there are only dots, lines, triangles, and other more complex geometric shapes are made up of triangles. including squares, circles, cubes, spheres and so on. But other, more complex objects, we can't all build on our own triangles, and this time we need to load a 3D model built using other software (such as 3DMax).

Projection

OpenGL ES The world is 3D, but the mobile phone screen can show me after all is a plane, but in the process of drawing the use of colors and lines so that the screen shows the effect of 3D. OpenGL ES makes this conversion process from 3D to 2D easier to set than the user by using the projection method.
There are two kinds of projection modes in OpenGL es: orthogonal projection and perspective projection. Orthogonal projection, the object does not vary in size from the location of the observation point. and perspective projection, the farther away from the observation point, the smaller the object, the nearer the observation point, the larger the object.

Light

It is difficult to make the 3D scene have a strong sense of reality if we use the color rendering directly to render the objects in the 3D scene. Generally speaking, curved objects can reflect the illumination effect more than plane objects. It is hard to simulate real-world illumination in a mathematical model, and the illumination model used in OpenGL ES 2.0 is much simpler than real-world illumination. In OpenGL ES 2.0, light is composed of three elements (or three channels), respectively, ambient light, specular light and scattered light.

Environment light means to illuminate the object from all directions, its specific formula is:

Ambient light exposure = material reflection coefficient ∗ ambient light intensity

Scattering light refers to the actual world of grass in the surface of the body is irradiated by light, reflected light in all directions of the basic uniformity of the situation, the specific formula is:

Scattering light irradiation result = reflection coefficient of material ∗ scattering light intensity ∗max (cos (angle of incidence), 0)

The actual development is often calculated in two steps:

Ultimate intensity of scattering light = scattering light intensity ∗max (cos (angle of incidence), 0)

Scattering light irradiation result = reflection coefficient of material ∗ scattering light ultimate strength

Mirror light refers to the real world in the smooth surface is illuminated by the direction of a very concentrated reflected light, and the ultimate intensity of scattering light depends on the incident light and the point of exposure of the normal vector angle, the intensity of the mirror is also dependent on the position of the observer, the specific formula is as follows:

In actual development, it is often calculated in two steps:

Texture mapping

Objects in the real world are often colorful, to simulate the real world of colorful, to draw a more realistic, cool 3D objects, you need to use texture mapping. A texture map maps a 2D texture to a stereo object in a 3D scene.

Other

Additional details such as 3D model loading, texturing, shading, particles, mixing and fog, signage, sky boxes, and knowledge follow up with the Sky Dome are described in detail.

OpenGL ES 2.0 Process and understanding

The OpenGL ES 2.0 rendering process can be seen from the OpenGL ES 2.0 rendering pipeline diagram:
Reads the vertex data--Performs the vertex shader--the assembly entity--raster entity--Executes the slice shader--Writes the frame buffer--displays to the screen.

    • OpenGL runs directly on the hardware as a local library, no virtual machines, no garbage collection, or memory compression. The data in the Java layer that defines the image needs to be accessible by OpenGL, so it is necessary to copy the memory from the Java heap to the local heap.
    • A vertex shader is a program that is executed for each vertex and is the location of each vertex. Similarly, the chip shader is for each piece of the program will be executed, determine the color of each piece.
    • The shader needs to be compiled and then linked to the OpenGL program. An OpenGL program is to link a vertex shader and a fragment shader together into a single object.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.