Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Transparent text to the second layer image  (Read 2165 times)

0 Members and 1 Guest are viewing this topic.

marianexyx

  • Newbie
  • *
  • Posts: 11
    • View Profile
Transparent text to the second layer image
« 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?



window.clear();
window.draw(background);
window.draw(rectangle);
text.setColor(Color(0,0,0,150));
window.draw(text);
window.display();
« Last Edit: March 25, 2015, 12:33:10 pm by marianexyx »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Transparent text to the second layer image
« Reply #1 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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

marianexyx

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Transparent text to the second layer image
« Reply #2 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Transparent text to the second layer image
« Reply #3 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
« Last Edit: March 25, 2015, 05:31:10 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/