SFML community forums

Help => Graphics => Topic started by: underww on January 29, 2018, 03:31:53 pm

Title: Is it possible to make full white sprite?
Post by: underww on January 29, 2018, 03:31:53 pm
I'm trying to make the sprites white shortly when characters take damage.
Some solutions I found are making white images by hand then swap the sprites or using shaders.

I don't like both solutions for a couple of reasons.
(There're a lot of images and I change the images often. and also I don't want to use shader for now.)

I was trying to make the white sprite using sf::BlendMode, but I could make only white sprite with black background.
(It seems because of the transparent area of the images.)

So I want to know if it is possible to make full white sprite without making white image or shader.
Thanks in advance. :)
Title: Re: Is it possible to make full white sprite?
Post by: Paul on January 29, 2018, 05:53:35 pm
In OpenGL it's possible even without shaders:

// Set color, your case
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB,  GL_REPLACE );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB,  GL_PRIMARY_COLOR_ARB );
 

// Mix colors
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
 

But I'm not sure if it's in any SFML functions.
Title: Re: Is it possible to make full white sprite?
Post by: Laurent on January 29, 2018, 06:54:37 pm
No, this is not exposed in SFML. Maybe you can call these functions directly and get what you want when drawing with SFML, but I wouldn't do that. It's a pretty old and limited way to do it, if it was me I'd definitely go with a fragment shader.
Title: Re: Is it possible to make full white sprite?
Post by: Hapax on January 29, 2018, 11:12:03 pm
I created some simple, quite generic, shaders a while back called (Lens (https://github.com/Hapaxia/Lens)) and one of them could do this for you, if you do choose the shader route.

Try this one:
https://github.com/Hapaxia/Lens/blob/master/Lens/blendColor.frag

In this shader, it just replaces all colours in the texture with the colour given to the drawable (sprite etc.); the transparency remains the same. It does this instead of 'multiplying' the colour with texture as is the default state (without shaders). The 'amount' uniform simply sets how much of this effect should apply. Anything from zero (original texture) and one (only the specified colour). So, for this effect, simply set the uniform 'amount' to 1.
Title: Re: Is it possible to make full white sprite?
Post by: underww on January 30, 2018, 02:55:06 pm
Thanks for the answers. I'll try some.