Android OpenGL learning notes

Source: Internet
Author: User

Http://www.cnblogs.com/shengdoushi/archive/2011/01/13/1934181.html#viewSource

Http://www.douban.com/note/74862515/

Http://blog.csdn.net/hecker385/article/details/6678621

 

 

Create an openglrenderer to implement the glsurfaceview. Renderer interface:

  • Onsurfacecreated: This method is mainly used to set parameters that do not change frequently during painting, such as background color and whether to enable Z-buffer.
  • Ondrawframe: defines the Actual Drawing operation. Refresh the call.
  • Onsurfacechanged: if the device supports horizontal and vertical screen switching, this method will occur in vertical swapping. In this case, you can reset the aspect ratio.

Glsurfaceview has two rendering modes: one is continuous screen update, and the other is on-demand, setrendermode (glsurfaceview. rendermode_when_dirty), only when calling requestrender () on the update screen. The default value is rendermode_continuously. The screen is refreshed continuously.

 

Generally, the process of texture ing is as follows:

  1. Create a texture object. Is to obtain a new texture Handle ID.
  2. Specify the texture. In this step, the image data is formally loaded into the ID's texture object.
  3. Set the filter. Defines the effects of OpenGL realistic images, such as mosaic elimination during texture enlargement.
  4. Bind a texture object. The ID texture is used as the texture for the following operations.
  5. Texture ing. Draw the texture data to the screen. In this step, you can see the effect of the texture.

In fact, the most important thing is the three steps

1. Define the three-dimensional coordinates of a point. The four vectors below define the four points in the three-dimensional space, which is a plane.

-1.0f,-1.0f, 1.0f, // V0
1.0f,-1.0f, 1.0f, // V1
-1.0f, 1.0f, 1.0f, // v2
1.0f, 1.0f, 1.0f, // v3

2. Define the ing between Texture Materials and coordinates, that is, how the four corners of the graph are mapped to the above plane, that is, how they are pasted.
0.0f, 0.0f, // the lower left of the graph corresponds to V0. Here, only four corners are represented, not the graph length.
0.0f, 1.0f, // the bottom right of the graph corresponds to V1
1.0f, 0.0f,
1.0f, 1.0f,

3. A graph is mapped to a plane in dimension 3. The following figure shows the ing.
OpenGL ES only supports triangle painting, so you need to define how to draw the index of the triangle, that is, the array of vertices in the above 1.
0, 1, 3, // draw a triangle represented by v0, V1, and V3
0, 3, 2

The final code:

Gl. glbindtexture (gl10.gl _ texture_2d, textures [0]); // bind the loaded Material
Gl. glvertexpointer (3, gl10.gl _ float, 0, vertexbuffer); // set a three-dimensional vertex
Gl. gltexcoordpointer (2, gl10.gl _ float, 0, texturebuffer); // you can specify the ing between material dimensions 2 and 3.
Gl. gldrawelements (gl10.gl _ triangles, indices. length, gl10.gl _ unsigned_byte, indexbuffer); // draw a triangle Based on the indexes in 3.

 

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.