Anti-Spam and atomization

Source: Internet
Author: User
Reprinted from: http://hi.baidu.com/309805453/blog/item/d036802e91ad10e18b13990c.html 9.1 anti-walk sample
When using a computer to draw a graph, if you observe it carefully, you will find that the lines drawn on the screen are jagged, because the screen is composed of pixels one by one, when the line is drawn between two pixels, the computer displays the line in a similar way. Processing the sample effect is usually called a reverse sample.
A reverse image processing method is used. The common anti-sample processing is to fill a part of pixels with excessive colors of the image and the surrounding environment to make the image look more authentic and natural. It is relatively simple to manually complete the transition. OpenGL also uses the color transition to reverse the image. The process of completing the inverse sample of OpenGL computing is somewhat complicated.
9.1.1 against OpenGL
OpenGL implements a back-to-root processing of images on the screen. It mainly involves vertex, line, and image edge, as well as fog or color and texture interpolation. In fact, OpenGL uses the integrated algorithm and technology to draw a reverse image.
9.1.2 anti-sample functions and definitions
OpenGL is not complex in anti-sample processing. It only uses two types of statements and functions to define the startup and properties of anti-sample processing. First, let the program know that OpenGL has enabled the anti-sample function.
(1) Startup and shutdown.
OpenGL defines the following three different state variables using the functions of glenable () and gldisable () to enable and disable the backsample startup and shutdown.
Startup point anti-spam processing: glable (gl_point_smooth );
Shielding point anti-Image Processing: gldisable (gl_point_smooth );
Startup line anti-Image Processing: glable (gl_line_smooth );
Shielding line anti-Image Processing: gldisable (gl_line_smooth );
Start the polygon anti-Image Processing: glable (gl_polygon_smooth );
Gldisable (gl_polygon_smooth );
This function usually requires the help of a function. In special cases such as polygon anti-spam, the startup of fusion is essential because OpenGL needs to know how to use the fusion attribute for Anti-Spam processing. It should be noted that the anti-walk sample of a polygon is based on the three sides of a triangle, or is reversed Based on the edges of each pair of ordered vertices. If we use the fusion function to work together with the anti-image, such an anti-image will produce unexpected extra edges. This side is not drawn by the reader, but is reversed. The program follows the smooth and dark rendering order, combine the edges composed of various vertices with the colors that have been drawn to complete the draw edges of the third "new" color. The common fusion is only the fusion surface, and no special processing is performed on the edges, in contrast, this special processing completes the reverse processing of edges.
(2) The glhint () function defines the anti-sample property.
Operation Method Function
The glhint () function defines the fusion method:
Void glhint (glenum target, glenum Mode)
Glenume target: defines the anti-sample object
Glenum mode: defines the anti-sample method.
Target form: gl_fog_hint: Calculation of fog
Gl_point_smooth_hint: Calculate the reverse sample of a vertex.
Gl_line_smooth_hint: line anti-walk Calculation
Gl_polygon_smooth_hint: Calculate the inverse pattern of a polygon.
Gl_perspective_correction_hint: color and texture Interpolation Calculation
Mode: gl_fastest: the most efficient choice.
Gl_nicest: the best quality, that is, the best quality choice.
Gl_dont_care: no customer choice required

9.2 Atomization
Fog in nature is changeable, transparent, and indefinite, but it is difficult for computers to simulate such real fog. Generally, computer simulation only simulates cloud smoke, dense fog, and virtual scenes in nature. In other words, it processes scene objects on the screen through virtual processing, make them look like objects in the fog. This process is called atomization.
9.2.1 OpenGL Atomization
Like the anti-image, atomization is also a method for controlling the color and edge processing of objects. In OpenGL, when the atomization effect is activated, the objects to be drawn in the scenario are fused from the far and near ground to the fog color, so that long-distance objects are integrated into the fog color, close-up objects gradually become clearer.
OpenGL atomization is performed after changing matrices, illumination, and texture ing. Therefore, fog still works on the surfaces of objects mapped to textures.
For OpenGL, atomization is also a way to change the color of objects. Therefore, atomization will not only be applied in fog scenarios. In fact, in addition to increasing the sense of realism and stereoscopy of scenes, OpenGL can also use atomization to create complex scenes such as smoke, clouds, flame, and explosion, these scenarios can also be created using the Integrated transparency technology, but the computing workload will increase significantly, so atomization is generally used.
9.2.2 atomization functions and definitions
Only two types of statement functions define the initiation and Properties of atomization. First, let the program know that OpenGL has enabled the atomization function.
(1) Enable and disable the atomization function
Enable atomization: glable (gl_fog );
Shielding atomization: gldisable (gl_fog );
(2) Definition functions of attributes such as atomization operations
The glfog () function completes the definition of the atomization attribute, which has the following forms:
Void glfogf (glenum pname, glfloat P );
Void glfogi (glenum pname, glint P );
Void glfogfv (glenmu pname, const glfloat * P );
Void glfogiv (glenum pname, const glint * P );
The state variable pname can be defined in the following form. They can be used to define different attributes of OpenGL atomization:
Value of glenum pname:
A: gl_fog_mode: defines the atomization mode. Three values are included, which are defined by three different state variables. When pname is gl_fog_mode, p takes the following state parameters to define the calculation factor of fog:
Gl_exp: default value. Exponential changes
Gl_exp2: exponential change 2.
Gl_linear: linear variation
B: gl_fog_density: defines the fog concentration to be drawn. The default value is 1.0.
C: gl_fog_start: defines the atomization start point to be drawn. In linear computation, it indicates the close point to the viewpoint. The default value is 0.0.
D: gl_fog_end: defines the atomization end point to be drawn. In linear computation, it indicates the long-distance point to the viewpoint. The default value is 1.0.
E: gl_fog_color: defines the fog color to be drawn. In the RGB color mode, define the four components of the rgba color. The default value is (0.0, 0.0, 0.0, 0.0)
F: gl_fog_index: defines the fog color to be drawn and the index color value in the index color mode. The default value is 0.
For example, you can define an atomization process as follows:
Glable (gl_fog );
Glfloat fogc [4] = {1.0f, 1.0f, 1.0f, 1.0f };
Glfogfv (gl_fog_color, fogc );
Glfogi (gl_fog_mode, gl_linear );
Glfogf (gl_fog_density, 2.0 );
Glfogf (gl_fog_start, 2.0 );
Glfogf (gl_fog_end, 9.0 );
Glhint (gl_fog_hint, gl_dont_care );
.......
Gldisable (gl_fog );
Above 1st ~ The 8 statement indicates that the atomization function is Enabled: the fog is white, linear atomization is adopted, the concentration is 2.0, and the distance is 2.0 ~ 9.0. Backsample solution for Atomization: no customer choice is required. OpenGL automatically balances the rendering speed and quality based on the calculation amount and computing capability.
Do not close it after completing atomization.

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.