SFML community forums

Help => Graphics => Topic started by: Roose Bolton of the Dreadfort on November 30, 2012, 02:23:18 pm

Title: sf::circleshape gradient..
Post by: Roose Bolton of the Dreadfort on November 30, 2012, 02:23:18 pm
is it possible to have a fall off from the center off a circleshape? Say I want to use it as an overlay on top of a laser projectile, to give it some glow?
Title: Re: sf::circleshape gradient..
Post by: gyscos on November 30, 2012, 02:49:34 pm
A quick search returned :
http://en.sfml-dev.org/forums/index.php?topic=3473.0

Looking at his source, the guy basically draws each pixel separately. This, along with the absence of gradient class, makes me think SFML does not support gradient.

I think you're better off using a gradient bitmap, possibly re-colorizing it ; or perhaps some shader could do the trick.
Title: Re: sf::circleshape gradient..
Post by: Foaly on November 30, 2012, 02:49:43 pm
It is not possible directly with one of the classes SFML provides (ie SFML does not provied gradient classes). That means you have to implement it yourself. Take a look at the wiki though. This class (https://github.com/SFML/SFML/wiki/Source%3A-Color-Gradient) might be helpful to you.
Title: Re: sf::circleshape gradient..
Post by: Laurent on November 30, 2012, 03:11:48 pm
Custom shapes with gradients can easily be created with a vertex array: if you assign different colors to the vertices that compose a primitive (ie. a triangle or quad), these colors are linearly interpolated by the graphics card to fill the primitive, and you get a smooth gradient with no effort.
Title: Re: sf::circleshape gradient..
Post by: gyscos on November 30, 2012, 03:22:38 pm
But this doesn't work with circular gradients... :(
Maybe your could approximate it with many star-shaped triangles... :-S
Title: Re: sf::circleshape gradient..
Post by: Laurent on November 30, 2012, 04:10:13 pm
Everything is made of triangles, even circles.
Title: Re: sf::circleshape gradient..
Post by: gyscos on November 30, 2012, 04:25:22 pm
I was actually comparing it with the "ColorGradient" class posted above, which builded the gradient pixel-by-pixel. At this level, approximation is... acceptable :p