Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Graphics
»
Undoing Color to Alpha.
Print
Pages: [
1
]
Author
Topic: Undoing Color to Alpha. (Read 1858 times)
0 Members and 3 Guests are viewing this topic.
cheeseboy
Newbie
Posts: 36
Undoing Color to Alpha.
«
on:
December 16, 2014, 01:38:10 am »
I want to change color in image to alpha. I can do this with sf::image's createMaskFromColor however what's the best way to reverse this? Do I need to store two copies? or do I loop through all the pixels? or is there a better way?
Logged
Ixrec
Hero Member
Posts: 1241
Re: Undoing Color to Alpha.
«
Reply #1 on:
December 16, 2014, 01:48:35 am »
It's not clear what you're trying to ask. Do you have a texture that you want to draw on the window semi-transparently? Are you actually editing images within your program? When you say "image", are you talking about a .png file, an sf::Image, an sf::Texture, an sf::Sprite, an array of Uint8s or something else entirely?
For the typical use case of a game that draws a texture to the window with some transparency, you shouldn't be using sf::Image at all. Use an sf::Texture so the pixels live on the GPU, and draw() an sf::Sprite with that texture. The sprite has a color (which includes alpha) which the GPU will efficiently apply to the pixels at draw() time. The relevant tutorial is:
http://www.sfml-dev.org/tutorials/2.1/graphics-sprite.php
«
Last Edit: December 16, 2014, 01:52:26 am by Ixrec
»
Logged
Gambit
Sr. Member
Posts: 283
Re: Undoing Color to Alpha.
«
Reply #2 on:
December 16, 2014, 05:26:51 am »
I think (Correct me if I'm wrong), he knows that he can create a color mask with a sprite, but he wants to know if he can create a mask from alpha. I'm not sure how to go about it though.
Logged
Laurent
Administrator
Hero Member
Posts: 32498
Re: Undoing Color to Alpha.
«
Reply #3 on:
December 16, 2014, 08:00:42 am »
If your image initially had no alpha at all, then you know that every pixel with alpha == 0 was originally of the masked color. So reverting is easy, just go through all pixels and do the replacement.
Logged
Laurent Gomila - SFML developer
Print
Pages: [
1
]
SFML community forums
»
Help
»
Graphics
»
Undoing Color to Alpha.
anything