Color Blending function in OpenGL (ii)--anti-aliasing processing

Source: Internet
Author: User

color Blending function in OpenGL (ii)--anti-aliasing processing
            in OpenGL, another use of the hybrid feature is anti-aliasing processing. In most cases, a rendered fragment is mapped to a pixel on the computer screen. Because these pixels are square, we can usually see clearly the two different color boundaries, which are what we usually call the sawtooth. The appearance of the sawtooth can make people feel that the image is unnatural and affects the perception greatly. This sawtooth phenomenon is a weakness of images produced by computers, which has a negative impact on many of our requirements for rendering tasks as realistic as possible.
to eliminate jagged edges between primitives, OpenGL uses blending to blend the color of the clip, which is the color of the pixel's target color and the surrounding neighboring pixels. Essentially, on the edge of any entity, the pixel color extends slightly to the neighboring pixels, which results in a smooth pixel color. Turning on anti-aliasing is simple, first we must enable the blending function and set some settings for the blending function:
//Set blend factor Glblendfunc (Gl_src_alpha, gl_one_minus_src_alpha);// enable blending glenable (gl_blend);
We also need to make sure that the mixed equation is set to the Gl_add mode, which is also the default setting. After you enable blending and select the correct blend equation, you can call the Glenable function to antialiasing a point, line, or polygon (any solid entity) as follows:
//Enable point smoothing glenable (gl_point_smooth); //set to the best quality mode glhint (Gl_point_smooth_hint, gl_nicest); //Enable line smoothing glenable (gl_line_smooth); //set to the best quality mode glhint (Gl_line_smooth_hint, gl_nicest); //Enable polygon smoothing glenable (gl_polygon_smooth); //set to the best quality mode glhint (Gl_polygon_smooth_hint, gl_nicest);
However, we should be aware when using gl_polygon_smooth that we may want to use it to smooth the edges of solid geometric elements. But there are other rules that need to be implemented to achieve this goal. Also, antialiasing of solid objects is not commonly used, and a method known as multiple adoption is often a better choice. The Glhint method allows us to choose different implementations for antialiasing, Gl_fastest (fastest) or gl_nicest (the best), and we use the best-performing approach. In our sample program, enable before and after anti-aliasing, and watch for changes in points, lines, and polygon edges in the screen:

anti-aliasing is not turned on
      turn on anti-aliased processing
The sample program can switch between antialiasing and non-antialiasing rendering modes by responding to the right-click menu. This part of the sample program complete code has been put on GitHub, the need for Friends can refer to (https://github.com/dxm3dp/OpenGL-06-Smoother Click to open the link ).

This article is from Du Xiaomeng's blog, do not use for any commercial purposes, reproduced please maintain integrity and identify the source: Http://blog.csdn.net/haohan_meng

Color Blending in OpenGL (ii)-anti-aliasing processing

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.