SFML community forums

Help => Graphics => Topic started by: marianexyx on March 25, 2015, 12:20:17 pm

Title: Transparent text to the second layer image
Post by: marianexyx on March 25, 2015, 12:20:17 pm
I have 2 images. First is fullscreen, and it's my backgroud as sprite, second is one-color rectangle drawn on backgroud. Next I have text written on those layers. I want my text to be transparent to second layer which is backgroud. How to do this?

(http://i21.photobucket.com/albums/b280/marianexyx/text_on_rect_zpsqggsh6u5.png)

window.clear();
window.draw(background);
window.draw(rectangle);
text.setColor(Color(0,0,0,150));
window.draw(text);
window.display();
Title: Re: Transparent text to the second layer image
Post by: zsbzsb on March 25, 2015, 04:07:16 pm
So.... if I have it straight.

--- < Background alpha = 0
--- < Strip over background alpha = 0
--- < Text which is alpha = 255 and it causes a hole where the letters are to be punched in the strip so you can see straight through to the background.

This isn't possible with directly SFML, you will need to look into using shaders for this.
Title: Re: Transparent text to the second layer image
Post by: marianexyx on March 25, 2015, 05:20:20 pm
These shaders looks very complicated. I barely understand what is it.

Maybe it is possible to fill text "color" with backgroud texture? And the text will be some kind of sprite then? :P
Title: AW: Transparent text to the second layer image
Post by: eXpl0it3r on March 25, 2015, 05:29:33 pm
It sure is possible. Use a rendertexture and alpha blend your text onto the strip.
Then use that render texture and draw it to the window. ;)

Did once create a similar example: https://github.com/eXpl0it3r/Examples/blob/master/SFML/Flashlight.cpp