一、概念 “混合”是指两种颜色的叠加方式。在新图片将要渲染画到屏幕上的时候,将用在新图片中的红、绿、蓝和透明度信息,与屏幕上已经存在的图片颜色信息相融合。 说的具体
- struct CC_DLL BlendFunc
- {
- //! source blend function
- GLenum src;
- //! destination blend function
- GLenum dst;
- //! Blending disabled. Uses {GL_ONE, GL_ZERO}
- static const BlendFunc DISABLE;
- //! Blending enabled for textures with Alpha premultiplied. Uses {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}
- static const BlendFunc ALPHA_PREMULTIPLIED;
- //! Blending enabled for textures with Alpha NON premultiplied. Uses {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}
- static const BlendFunc ALPHA_NON_PREMULTIPLIED;
- //! Enables Additive blending. Uses {GL_SRC_ALPHA, GL_ONE}
- static const BlendFunc ADDITIVE;
- bool operator==(const BlendFunc &a) const
- {
- return src == a.src && dst == a.dst;
- }
- bool operator!=(const BlendFunc &a) const
- {
- return src != a.src || dst != a.dst;
- }
- bool operator<(const BlendFunc &a) const
- {
- return src < a.src || (src == a.src && dst < a.dst);
- }
- };
代码测试如下: [cpp] view plain copy
- //test 1
- Sprite* sp1 = Sprite::create("my_test/red.png");
- sp1->setPosition(Vec2(200, 200));
- addChild(sp1);
- Sprite* sp2 = Sprite::create("my_test/green.png");
- sp2->setPosition(Vec2(220,220));
- this->addChild(sp2);
- BlendFunc cbl = { GL_SRC_ALPHA , GL_ONE };
- sp2->setBlendFunc(cbl);
- //test 2
- Sprite* sp3 = Sprite::create("my_test/red.png");
- sp3->setPosition(Vec2(300, 200));
- addChild(sp3);
- Sprite* sp4 = Sprite::create("my_test/green.png");
- sp4->setPosition(Vec2(320,220));
- this->addChild(sp4);
- BlendFunc cb2 = {GL_ZERO, GL_ONE};
- sp4->setBlendFunc(cb2);
- //test 3
- Sprite* sp5 = Sprite::create("my_test/red.png");
- sp5->setPosition(Vec2(400, 200));
- addChild(sp5);
- Sprite* sp6 = Sprite::create("my_test/green.png");
- sp6->setPosition(Vec2(420,220));
- this->addChild(sp6);
- sp6->setBlendFunc(BlendFunc::DISABLE);
测试结果如下: