Hi all!
I was under the impression that I understood how BlendAdd works... but I don't apparently.
Take this testcase:
sf::RenderTexture source;
source.create(400, 400);
source.clear(sf::Color(255, 0, 0));
sf::RenderTexture target;
target.create(400, 400);
target.clear(sf::Color(0, 0, 0, 0));
sf::Sprite sprite(source.getTexture());
sprite.setColor(sf::Color(255, 255, 255, 127));
target.draw(sprite, sf::BlendAlpha);
sf::Color c = target.getTexture().copyToImage().getPixel(200, 200);
qDebug() << c.r << c.g << c.b << c.a;
(replace qDebug() with your favorite out stream..)
We create a source texture, fill it with 100% opaque red.
Then we paint the source texture over the (0, 0, 0, 0) cleared
target texture, with opacity set to
half (127) in Sprite::setColor().
Now, in using BlendAlpha, everything works as expected:
"127 0 0 127"
The opacity halves the red color value, and it is painted over the (0, 0, 0, 0) pixel.
The alpha value itself(!) remains unchanged, it is still 127.
Now, change the BlendAlpha above to BlendAdd. What happens is:
"127 0 0 63"
This is very unexpected. I was thinking the red value would get halved again,
the alpha would remain unchanged(!), and everything would just be added
to the (0, 0, 0, 0) resulting in (127, 0, 0, 127), but apparently, for some reason,
the alpha is multiplied by itself (ie. halved too)? How does that work, is it openGL specific?
And how could I possibly work around it?
What I would like to achieve is to have the target texture at full red (255, 0, 0, 255)
when I paint it using BlendAdd and half-opacity red.
Thanks.