Android learning notes: OpenGL drawing Summary

Source: Internet
Author: User

I don't need OpenGL ES drawing for a long time, so I'm afraid I forget it. So I review it again. By the way, the principles are summarized as follows:

1. Android 3D Coordinate System

In Android 3D Coordinate System:

Coordinates are located in the center,

The X axis is extended from left to right. The value on the left of the origin is negative and the value on the right is positive;

The Y axis is extended from bottom up. The value below the origin is negative and the value above is positive;

The Z axis screen is extended to the outside. The screen contains a negative number and a positive number outside.

 

2. Introduction to development tools (OpenGL and OpenGL ES)

OpenGL: Open graphics library, open graphics library interface, cross-programming language, cross-platform programming interface specifications. It is applicable to new workstations and personal PCs.

OpenGL ES: OpenGL for embedded system, a subset of OpenGL. Based on OpenGL, many non-essential features such as glbegin/glend, quadrilateral, and polygon are removed. Suitable for Embedded Systems with small devices.

 

3. Drawing Graphics Using OpenGL ES

(1) the OpenGL ES paint brush gl10 has two modes when drawing the image:

1, gl10.gl _ triangles: Draw a triangle

2, gl10.gl _ triangle_strip: Draw a polygon using multiple triangles

That is to say, OpenGL ES can only draw 3D images composed of triangles.

 

(2) gldrawarrays (INT mode, int first, int count );

When the first parameter is the second mode above, it indicates that the system will use multiple triangles to draw a polygon. From the first vertex, each three vertices will draw a triangle. For example, the data source we provided at the beginning contains four vertices (0, 1, 2, 3). Our method is gldrawarrays (gl10.gl _ triangle_strip,), which indicates that we will draw two triangles, A triangle consists of three vertices, 1, 2, and 1, 2, and 3, respectively. The drawn image is as follows:

Therefore, if the position of the source data is changed, the image also changes accordingly. For example, when we open the data source, the given point contains four points: (0, 1, 2, 3, the others are the same as above, but the position of the vertex has changed. The figure drawn is as follows:

(3) drawing a 3D image is similar to drawing a 2D image. The difference is that drawing a 3D image requires not only defining the coordinates of each vertex position, you also need to define the vertices that each triangle of a 3D image consists.

Like 2D, GL uses the following 3D rendering method: gldrawelements (INT mode, int count, int type, buffer indices ). Think about it. When we do not place the points for drawing 2D images on the same plane, the images are not 3D images, but 3D images, we also need to give the data source that combines the points of the drawn surface, that is, we must give several faces, each of which is composed of those points.

 

4. Steps for using OpenGL ES in Android

(1) Create the glsurfaceview component and use activity to display the glsurfaceview component.

(2) create a glsurfaceview. Renderer instance for the glsurfaceview component to implement the glsurfaceview. Renderer class. The interface should implement the three methods.

A. Abstract void ondrawframe (gl10 GL );

B. Abstract void onsurfacechanged (gl10 GL, int width, int height );

C. Abstract void onsurfacecreated (gl10 GL, eglconfig config );

(3) Call the setrenderer () method of the glsurfaceview component to create the Renderer object. This Renderer object will complete the drawing of 3D images in the glsurfaceview.

 

 

5. Differences between a three-dimensional coordinate system and a two-dimensional coordinate system

The coordinate value on a two-dimensional coordinate system usually uses the number of pixels of the system directly.

The coordinate value of the Three-coordinate system depends on the setting of the glfrustumf () method.

Glfrustumf (float left, float right, float bottom, float top, float znear, float zfar)

This method is used to set the space size of the Perspective Projection. The first two parameters are used to set the minimum and maximum coordinate values on the X axis, the two parameters are used to set the minimum and maximum coordinate values on the Y axis. The other two parameters are used to set the minimum and maximum coordinate values on the Z axis.

 

 

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.