it can be done by sf::RenderTexture like this
I think the blood effect would be an image/texture that is overlaid on top of the original image that does not exceed the edge of that original (they mentioned clipping already above). Unfortunately, I don't think your solution achieves that.
You can achieve this using a render texture (as Mortal mentioned) though.
You can use the alpha channel of the base image directly.
Draw the image to be overlaid on an empty (transparent) render texture.
Draw the base image also onto the render texture using a blend mode that takes into account the alpha of the base image as well (ignore the base image's colour).
Use the render texture instead of the image to be overlaid.
Here's an example:
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::Texture clipTexture, overlayTexture;
if (!clipTexture.loadFromFile("sfml-logo-small.png") ||
!overlayTexture.loadFromFile("blood.png"))
{
std::cerr << "Unable to load textures." << std::endl;
return EXIT_FAILURE;
}
sf::Sprite clipSprite(clipTexture);
sf::Sprite overlaySprite(overlayTexture);
sf::RenderWindow window(sf::VideoMode(clipTexture.getSize().x, clipTexture.getSize().y), "Clip Sprite", sf::Style::Default);
window.setFramerateLimit(60);
sf::BlendMode blendMode(sf::BlendMode::Zero, sf::BlendMode::One, sf::BlendMode::Add, sf::BlendMode::DstAlpha, sf::BlendMode::OneMinusSrcAlpha, sf::BlendMode::Subtract);
sf::RenderTexture renderTexture;
renderTexture.create(clipTexture.getSize().x, clipTexture.getSize().y);
renderTexture.clear(sf::Color::Transparent);
renderTexture.draw(overlaySprite);
renderTexture.draw(clipSprite, blendMode);
renderTexture.display();
sf::Sprite renderSprite(renderTexture.getTexture());
bool showOverlay{ true };
bool showBase{ true };
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed || event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
window.close();
if (event.type == sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::Num1) // press 1 to toggle base/clip image
showBase = !showBase;
else if (event.key.code == sf::Keyboard::Num2) // press 2 to toggle overlay image
showOverlay = !showOverlay;
}
}
window.clear(sf::Color::Blue);
if (showBase)
window.draw(clipSprite);
if (showOverlay)
window.draw(renderSprite);
window.display();
}
return EXIT_SUCCESS;
}
Both base sprite and overlaid sprite (clipped):
Overlaid sprite only (still clipped):
I have attached the two images (SFML logo and blood) so that you can try out this code as is.
EDIT: slightly modified provided code so that the window size is based on the size of the first texture, as is shown in the screenshots.