1
Graphics / [SFML 2.0] Simple color changing frag-shader does not work
« on: October 13, 2012, 07:49:56 pm »
Hey
I would like to change the color palette as an effect.
So I could replace all colors with just two different colors, so basically changing the color depth to 1 bit.
I decided to use the fragment shader :
And the sfml-part :
But all what happens is that the the sprite applied with this shader goes black.
Any help would be appreciated!
I would like to change the color palette as an effect.
So I could replace all colors with just two different colors, so basically changing the color depth to 1 bit.
I decided to use the fragment shader :
uniform vec4 on_bit;
uniform vec4 off_bit;
void main()
{
vec4 pixel = gl_Color;
if (pixel.r < 255 || pixel.g < 255 || pixel.b < 255)
pixel = on_bit;
else
pixel = off_bit;
gl_FragColor = pixel;
}
uniform vec4 off_bit;
void main()
{
vec4 pixel = gl_Color;
if (pixel.r < 255 || pixel.g < 255 || pixel.b < 255)
pixel = on_bit;
else
pixel = off_bit;
gl_FragColor = pixel;
}
And the sfml-part :
if (!sf::Shader::isAvailable() ||
!m_ShaderContainer[0].loadFromFile("data//Shader//1bbp.frag", sf::Shader::Fragment))
{
// error messages
}
else
{
std::cout << "Engine : Shader OK !\n";
m_ShaderContainer[SHADER_1BPP].setParameter("on_bit", sf::Color::Black);
m_ShaderContainer[SHADER_1BPP].setParameter("off_bit",sf::Color::White);
}
!m_ShaderContainer[0].loadFromFile("data//Shader//1bbp.frag", sf::Shader::Fragment))
{
// error messages
}
else
{
std::cout << "Engine : Shader OK !\n";
m_ShaderContainer[SHADER_1BPP].setParameter("on_bit", sf::Color::Black);
m_ShaderContainer[SHADER_1BPP].setParameter("off_bit",sf::Color::White);
}
But all what happens is that the the sprite applied with this shader goes black.
Any help would be appreciated!