Some experiments on Template Cache

Source: Internet
Author: User

Many tests of OpenGL demonstrate "great" operability everywhere, the most common Alpha testing, cropping testing, and deep testing .. However, they all have their own purposes. There is a template test, and the parameters are "complicated ". After reading the Redbook, I cannot explain it. It is really not representative that I dare not say anything about the example in the Redbook. Google is not a thorough understanding on the Internet (especially those who directly copy other people's code, I sincerely appreciate their perseverance in misunderstanding ~~). After all, this is the first SGI product in the United States. It is more practical and can be deeply rooted in the essence of the old Midea data. Finally found some useful information on the OGL official website (http://www.opengl.org/code. URL:

 

Http://psysal.livejournal.com/67933.html

Http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node117.html

Http://www.opengl.org/sdk/docs/man/xhtml/glStencilFunc.xml

 

If you are interested in it, you will surely be enlightened (if you are vague about stencel ~).

 

The following is my test summary:

 

First, let's talk about how to use it (first, your hardware (video card) should support stencer cache)

1. Win32 pixel format, set the template bit/glut to initialize the display mode or use

2. Set the refresh default value: glclearstencel (0); // set it to 0, which can be modified as needed.

3. frame-by-frame Refresh: glclear or gl_stencel

4. Enable the template cache test in the appropriate places: gl_stencil_test );

5. Set the template value and template test result operations as needed: glstencilfun (func, Val, mask); glstencilop (failed, zfailed, zpass );

 

Well, you have to do this, but you need to understand some tips:

First, let's talk about the significance of template caching. Why is it necessary and what it will do. We know that the cropping test is used to define the display range. The Alpha test uses the color dependency to filter the display (more results can be achieved by combining the mixture ), deep testing is to make 3D objects according to the Z value mutual cover (so also known as "Z-BUFFER "). So how can I implement this when I want to specify an element or element set as my filter (mask? The preceding tests obviously cannot meet the requirements. As a result, stencel is generated. It is similar to the deep cache (it can be understood as "Deep cache in a region", for personal opinions, haha ~~). OK. Everything is clear. (For the function usage and parameter meanings, you can refer to the above URL or the Redbook)

Secondly, sometimes we do not need to display this mask. Friends who have used Adobe products should have a better understanding of this (PS and AE have similar concepts ). Therefore, we can use glcolormask (gl_false, gl_false) to completely disable the write operation to the color buffer (that is, no color information is displayed ). After you have painted the template mask, remember to restore it. Otherwise, your scenario will be "Black. Another is to use gldepthmask to control write operations on the deep cache to achieve more results.

 

Start test:

 

When you understand how to use template caching, everything can be done as you like. Here, I first fl the full background template value to 1, then forcibly write the ground to 0, and then pass the test when the teapot is greater than 1. (Of course, the template cache is disabled elsewhere. And I will draw the ground first and then the teapot .). The effect is as follows:

 

 

 

That's easy ~ Everything goes smoothly. Go to the next step and properly close the color writing on the ground (the first time left a red weight, and the second time all closed .). The effect is as follows:

 

 

 

 

Well, that's it. Everything is exactly the same as expected. OK, now I want to turn off the write of the deep cache so that the teapot can be seen in the lower-and up-the-ground view. Is this cool ~ It's like a two-sided magic door. OK. The effect is as follows:

 

 

 

 

 

Haha, although it has achieved the expected results (dual-sided fluoroscopy ). But this teapot looks strange (haha, yes, it seems like there is no deep detection ). That's because I turned off the deep writing, so the depth of the teapot itself seems abnormal. OK. Now the problem is found. Fix it! Enable and disable the function before you enable the function.

Then, the following is: (well, it is like this ~ Everything works)

 

 

 

 

OK. This is the end of the test. Haha, this is just a test, very simple. Of course, you can use it to create a variety of strange or unexpected combinations to implement various hollow-out and other special effects .~

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.