SFML community forums
Help => Graphics => Topic started by: Megatron on November 17, 2010, 07:48:59 pm
-
I was wondering if it's possible to have a sprite who's tranparency changes from side to the other? For instance, I have a sprite that I want to be fully visible at the top but then fade to transparent by the time I hit the bottom. Would you have to use shaders for this?
Thanks
-
What if you just set the image's pixel's transparency by hand? sf::Sprite::GetImage() gives you the image, and then you can modify it's pixels. :)
-
You can create a generic mask/layer/whatever it is called image for it. You just render it above the image you want and set the global color of the sprite. Never tried but I think it should work.
-
No, no, what (s)he is asking is different from what you guys answered.
What you want is a perfect example on when to use shaders.
The shader should be something like this (I'll be overly verbose for clarity. You might want to do it all in a single line)
uniform sampler2D current; //set this to sf::Shader::CurrentTexture as explained in the tutorials
void main()
{
vec2 thisposition = gl_TexCoord[0].xy;
float alpha = thisposition.y; //this is the y coordinate, from 0 to 1
vec4 pixel = texture2D(current, gl_TexCoord[0].xy);
pixel.a = alpha;
gl_FragColor = pixel;
}