Cocos2dx Sprite setBlendFunc color mixing: addition, subtraction

Source: Internet
Author: User

CCSprite has a ccBlendFunc-type blendFunc _ struct Member, which can be used to set the color mixing scheme during plotting. CcBlendFunc contains a src and a dst, indicating the target and source operators respectively.

If we use the setBlendFunc Method for a Sprite, for example:

CCSprite: setBlendFunc (ccBlendFunc blendFunc );

This Sprite will be used as the source, and the pixel of the position where the Sprite is located will be used as the target for Hybrid Operation:

Source RGBA variables: Rs, Gs, Bs,;

Target RGBA: Rd, Gd, Bd, Ad;

Each operational factor of the source:N_Rs, N_Gs, N_Bs, N_As;

Each operational factor of the target: N_Rd, N_Gd, N_Bd, N_Ad;

The RGBA is: (Rs * N_Rs + Rd * N_Rd, Gs * N_Gs + Gd * N_Gd,

Bs * N_Bs + Bd * N_Bd, As * N_As + Ad * N_Ad)

The calculation factors include:

GL_ONE: 1.0

GL_ZERO: 0.0

GL_SRC_ALPHA: the Alpha value of the source as a factor.

GL_DST_ALPHA: Target Alpha as a factor

GL_ONE_MINUS_SRC_ALPHA: 1.0 minus the source Alpha value as a factor

GL _ ONE_MINUS_DST_ALPHA: 1.0 minus the Alpha value of the target as a factor

We can see in the init method of CCSprite that the GL_ONE and GL_ONE_MINUS_SRC_ALPHA parameters are used by default. This is what we see. Sprite will overwrite the following description, however, if there is transparency, the following color values will be displayed. Let's take a look at the effects of using each parameter:


We can see in the init method of CCSprite that the GL_ONE and GL_ONE_MINUS_SRC_ALPHA parameters are used by default. This is what we see. Sprite will overwrite the following description, however, if there is transparency, the following color values will be displayed. Let's take a look at the effects of using each parameter:

0: do not change the mix, use the default situation:

1: If glBlendFunc (GL_ONE, GL_ZERO) is set, the source color is used completely on the surface, that is, the effect is the same as that of not mixing, but if Sprite itself is transparent, then the transparent area turns black. Because the target color is not displayed at this time. It makes no sense even if the transparency is 0.

2: If glBlendFunc (GL_ZERO, GL_ONE) is set, the Sprite will not be drawn if the source color is not used.

3: The ALPHA-related factor is calculated based on transparency. For example, the color with high transparency accounts for a large proportion. By default.

Appendix:

Constant Correlation factor Fusion factor result
GL_ZERO Source factor or Target Factor (0, 0, 0)
GL_ONE Source factor or Target Factor (1, 1, 1)
GL_DST_COLOR Source factor (Rd, Gd, Bd, Ad)
GL_SRC_COLOR Objective factor (Rs, Gs, Bs,)
GL_ONE_MINUS_DST_COLOR Source factor (1, 1, 1)-(Rd, Gd, Bd, Ad)
GL_ONE_MINUS_SRC_COLOR Objective factor (1, 1, 1)-(Rs, Gs, Bs,)
GL_SRC_ALPHA Source factor or Target Factor (As,)
GL_ONE_MINUS_SRC_ALPHA Source factor or Target Factor (1, 1, 1)-(As,)
GL_DST_ALPHA Source factor or Target Factor (Ad, Ad)
GL_ONE_MINUS_DST_ALPHA Source factor or Target Factor (1, 1, 1)-(Ad, Ad)
GL_SRC_ALPHA_SATURATE Source factor (F, 1); f = min (As, 1-Ad)


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.