I think something like this (
untested):
sf::CircleShape point(10);
point.setColor(255, 255, 255, 1);
sf::RenderTexture rtex;
rtex.create(windowWidth, windowHeight);
rtex.clear();
rtex.draw(point, sf::BlendNone);
rtex.display();
sf::Sprite sprite;
sprite.setTexture(rtex.getTexture());
// ...
window.draw(sprite);
Interesting enough the alpha channel of the circle/punch hole, can't be fully transparent, otherwise it will just be ignored.
@Laurent is this the intended behavior?
Anyways since I found the question interesting and somehow on another board has asked about the same questions here goes a complete example:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(300, 300), "Hello World!");
window.setFramerateLimit(30);
window.setMouseCursorVisible(false);
sf::RectangleShape rect(sf::Vector2f(100.f, 100.f));
rect.setFillColor(sf::Color::Red);
rect.setPosition(10, 10);
sf::CircleShape circle(20);
circle.setRadius(20);
circle.setPosition(110, 110);
circle.setFillColor(sf::Color(255, 255, 255, 1));
sf::RenderTexture rtex;
rtex.create(300, 300);
sf::Sprite sprite;
sprite.setTexture(rtex.getTexture(), true);
sprite.setPosition(0, 0);
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
circle.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)));
rtex.clear();
rtex.draw(circle, sf::BlendNone);
rtex.display();
sprite.setTexture(rtex.getTexture(), true);
window.clear(sf::Color::Blue);
window.draw(rect);
window.draw(sprite);
window.display();
}
}
But keep in mind drawing to the render texture every frame is quite a heavy task, it's like drawing two frames at once, so if it's not really needed don't do this every frame iteration.