I'm trying to create a outline effect to my buttons when they are clicked but atm I'm just testing stuff with shaders... whenever I draw something with my shader tho it renders the shape completely black
#include <SFML\Graphics.hpp>
int main(){
sf::RenderWindow window(sf::VideoMode(500, 500), "hello world", sf::Style::Close);
sf::RectangleShape rect;
rect.setSize(sf::Vector2f(100, 100));
rect.setFillColor(sf::Color::Red);
sf::Shader blur;
if (!blur.loadFromFile("blur.frag", sf::Shader::Fragment)){
return 1;
}
if (!blur.isAvailable()){
return 1;
}
blur.setUniform("texture", sf::Shader::CurrentTexture);
blur.setUniform("blur_radius", 0.002f);
while (window.isOpen()){
sf::Event evnt;
while (window.pollEvent(evnt)){
if (evnt.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color(0, 100, 100));
sf::RenderStates state;
state.shader = &blur;
window.draw(rect, state);
window.display();
}
return 0;
}
and my shader code.
uniform sampler2D texture;
uniform float blur_radius;
void main()
{
vec2 offx = vec2(blur_radius, 0.0);
vec2 offy = vec2(0.0, blur_radius);
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * 4.0 +
texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
texture2D(texture, gl_TexCoord[0].xy + offx) * 2.0 +
texture2D(texture, gl_TexCoord[0].xy - offy) * 2.0 +
texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
gl_FragColor = gl_Color * (pixel / 16.0);
}
I would expect a blurred red rectangle to appear in the top left cornor but instead theres a black solid rectangle.