Parameters of glblendfunc ()

Source: Internet
Author: User

When we see the OpenGL hybrid chapter, it seems that glblendfunc function parameters are hard to understand:

OpenGL extracts the source color and the target color respectively and times the coefficient (the source color multiplied by the coefficient is called the "source factor", and the target color multiplied by the coefficient is called the "Target Factor "), then add the new colors. (Or not adding. The new version of OpenGL can be used to set the calculation method, including adding, subtracting, and obtaining larger values of the two, smaller values of the two, and logical operations, but we will not discuss this here for the sake of simplicity)
The following uses mathematical formulas to express this calculation method. Assume that the four components of the source color (red, green, blue, and alpha) are (RS, GS, BS, as), and the four components of the target color are (Rd, Gd, BD, AD), and the source factor is (Sr, SG, Sb, SA), and the target factor is (DR, DG, DB, DA ). The new color generated by the hybrid operation can be expressed:
(RS * Sr + RD * Dr, GS * SG + GD * DG, BS * Sb + bd * dB, as * Sa + Ad * Da)
Of course, if a certain color component exceeds 1.0, it will be automatically truncated to 1.0, and the problem of crossing the border does not need to be considered.


The source and target factors can be set through the glblendfunc function. Glblendfunc has two parameters. The former indicates the source factor, and the latter indicates the target factor. These two parameters can be multiple values. The following describes several commonly used parameters.

Gl_zero: 0.0 is used as the factor, which is equivalent to not using this color for hybrid operation.

Gl_one: 1.0 is used as the factor. In fact, this color is used completely in the hybrid operation.

Gl_src_alpha: indicates that the alpha value of the source color is used as a factor.

Gl_dst_alpha: Use the Alpha value of the target color as a factor.

Gl_one_minus_src_alpha: Used to subtract the Alpha value of the source color from 1.0 as a factor.

Gl_one_minus_dst_alpha: the Alpha value of the target color minus 1.0 is used as a factor.
In addition, there are gl_src_color (four components of the source color are used as the four components of the factor respectively), gl_one_minus_src_color, gl_dst_color, and gl_one_minus_dst_color. The first two components can only be used to set, the last two versions of OpenGL can only be used to set source factors. The new version of OpenGL does not have this restriction, and supports the new gl_const_color (set a constant color and use its four components as the four components of the factor respectively), gl_one_minus_const_color, gl_const_alpha, and gl_one_minus_const. In addition, there is gl_src_alpha_saturate. The new version of OpenGL also allows different mixing factors for the Alpha and RGB values of colors.


For example:
If glblendfunc (gl_one, gl_zero); is set, the source color is used completely, and the target color is not used at all, therefore, the image effect is the same as that when the image is not mixed (of course, the efficiency may be a little lower ). If the source and target factors are not set, this is the default setting.
If glblendfunc (gl_zero, gl_one); is set, the source color is not used at all. Therefore, no matter what you want to draw, it will not be painted at last. (But this does not mean that this setting is useless, and sometimes it may be used for special purposes)
If glblendfunc (gl_src_alpha, gl_one_minus_src_alpha) is set, the source color is multiplied by its own Alpha value, and the target color is multiplied by 1.0 minus the Alpha value of the source color, the larger the Alpha value of the source color, the larger the proportion of the source color in the new color, and the smaller the proportion of the target color. In this case, we can simply think of the Alpha value of the source color as "opacity ". This is also the most common method for mixing.
If glblendfunc (gl_one, gl_one); is set, the source color and the target color are used completely. The final color is actually a simple addition of the two colors. For example, red (1, 0, 0) and green (0, 1, 0) are added to get (1, 1, 0), and the result is yellow.


Note:
The source color and target color are related to the draw sequence. If a red object is first drawn, then a green object is drawn on it. Green indicates the source color, and red indicates the target color. If the order is reversed, red indicates the source color, and Green indicates the target color. When drawing, pay attention to the order, so that the source color of the painting corresponds to the set source factor, and the target color corresponds to the set target factor. Do not get dizzy in a disordered order.



This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/aurora_mylove/archive/2007/07/20/1700540.aspx

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.