I am trying to overlay one texture on top of another one. Both textures have semi-transparent areas. Expected result: like layers in Photoshop or other raster graphics editors (image 1). I am trying to do this by drawing both textures in RenderTexture one by one.
But I have two problems:
1. When simply drawing a texture on top of a transparent RenderTexture, a dark stroke appears along semi-transparent the contour (image 2). I already found a solution to use BlendMode(BlendMode::One, BlendMode::OneMinusSrcAlpha).
2. This problem occurs when trying to solve the first one. If I only apply BlendMode to the first texture, it draws fine, but the second texture makes the transparent part of the first texture opaque (images 3, 4). Applying BlendMode to both textures produces completely inappropriate result.
Is there a way to solve both problems and achieve the effect of overlaying layers like in raster graphics editor?
sf::BlendMode blendMode(sf::BlendMode::One, sf::BlendMode::OneMinusSrcAlpha);
sf::Texture tex0;
tex0.loadFromFile("layer_0.png");
sf::Texture tex1;
tex1.loadFromFile("layer_1.png");
sf::RenderTexture rtex;
rtex.create(width, height);
rtex.clear(sf::Color::Transparent);
rtex.draw(sf::Sprite(tex0), blendMode);
rtex.draw(sf::Sprite(tex1));
rtex.display();
sf::Texture layers = rtex.getTexture();
layers.copyToImage().saveToFile("layers.png");