Original geolo article. For more information, see EOE Forum http://www.eoeandroid.com/thread-66461-1.html source.
Note: This article sets the technology and Code on the network and has been modified by myself (this is an apology to the original author ). The best place to learn OpenGL is to read the nehe article)
This time the Code is not written in the article, and it takes a lot of space. You can download the source code and read this article.
I. mengban technical steps (Transfer: http://goodidea.blog.51cto.com/639065/195158)
It looks like the effect of the mask inside the carved wall.
Procedure:
1. The carved wall is a texture. The wall is colored and the hollow area is black. It is pre-generated with the same black and white texture to make the hollow area white and the wall black.
2. Draw a landscape inside the wall
3 glblendfunc (gl_dst_color, gl_zero); Draw black and white textures
The hybrid factor corresponding to gl_dst_color is (Rd, Gd, BD, AD), that is, the color of the original pixel in the frame cache. Multiply the black-and-white texture with gl_dst_color. If the wall is black, the result is black. If the hollow area is white, the result is the color in the original pixel.
4 glblendfunc (gl_one, gl_one );
Texture of carved walls
The place where the carved wall is hollow-out is black, then the original color is used. In the previous rendering, the hollow-out area is the original wall landscape. The wall part = the current color + the color after step 2. In step 1, the wall is black, that is, if the value is 0, the Wall Part = current color + 0 = current color
Ii. Definitions of OpenGL depth, deep caching, and deep Testing
1. Depth: the distance between the currently drawn pixels and the eye
2. Deep cache-this cache stores the depth value of each pixel to be drawn
3. Deep test: two States. One is to draw pixels from a long distance, and the other is to be closer. The default value is relatively close, which gives a much-preferred perspective. After the perspective state is enabled, you can see that a person is standing on the rails. The line of sight is parallel to the track, and the bilateral sides of the rails are gathered to a point in the distance.
3. Why the MASK technology?
When we have multiple textures mapped to the same position of a polygon at the same time, if we use a common mixed pattern, the colors will overlap, without the effect of looking at objects through mosquito nets.
4. Two steps of nehe masking Technology
A. First, we place black and white textures on the scene. White represents the transparent part, and black represents the opaque part.
B. Then we use a special blending method. Only the texture on the black part is displayed on the scene.
Black and white texture 1
Figure 1.
Figure 2
Background Image
5. Steps and principles of masking in project code
1. We use the gldrawelements method in the code to split the tag.
2. Use the gldrawelements method for the first time to draw a square and texture the background image.
3. Start the Gl. glable (gl10.gl _ blend) hybrid function );
4. Disable the deep test Gl. gldisable (gl10.gl _ depth_test). After the mask is successful, we still need to enable the deep test. The second part has explained the meaning of depth.
5. A special mixed effect glblendfunc (gl10.gl _ dst_color, gl10.gl _ zero). Here, the meaning is to multiply the pixels of the background image by the pixels of Figure 1 to get the pixels of a new image. Because the pixels are black (,) and white (,), the pixels multiplied by the black ones become black (x * 0 = 0 ). the part that is multiplied by the white color is still white. Is an operation
6. Use the gldrawelements method for the second time to draw out the masked effect.
7. Since the front mask is not all black and white pixels, it will also be doped with RGB pixels. Therefore, the result of multiplication will give the background image a Glass Shadow effect. Therefore, we need to plot Figure 2 at this time. Figure 2 directly paste it to overwrite it. How can I paste it ??
8. here we need to use another special color mixing effect for glblendfunc (gl10.gl _ One, gl10.gl _ one ); the effect here is to add the pixels of the new image to the pixels of Figure 2 and then get the latest image pixels... Is a plus operation.
9. The last time we used the gldrawelements method to draw the mask, this is what we need.
10. The code example adds an animation to the background image and texture image to make the display effect more obvious.
: The image has been compressed, and the distortion is very high .....
Project code: Go to EOE Forum download: http://www.eoeandroid.com/thread-66461-1-1.html