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:
- Create a texture object. Is to obtain a new texture Handle ID.
- Specify the texture. In this step, the image data is formally loaded into the ID's texture object.
- Set the filter. Defines the effects of OpenGL realistic images, such as mosaic elimination during texture enlargement.
- Bind a texture object. The ID texture is used as the texture for the following operations.
- 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.