Hello
Basically, I'm doing the following:
(SFML 2.1 statically linked)
void TestFunc ()
{
sf::RenderWindow Window;
Window.create(sf::VideoMode(800, 600), "TestFunc");
//rect
sf::RectangleShape Rect;
Rect.setPosition(300.0f, 200.0f);
Rect.setSize(sf::Vector2f(200.0f, 100.0f));
Rect.setOutlineThickness(4);
Rect.setFillColor(sf::Color(0, 0, 0, 0));
Rect.setOutlineColor(sf::Color(0x00, 0x33, 0xff));//light blue
//texture to render into
sf::RenderTexture RenderTexture;
bool bRes = RenderTexture.create(512, 512);
if (bRes == false) return;
//pixelate shader from examples
sf::Shader ShaderPixelateF;
bRes = ShaderPixelateF.loadFromFile("dat/shaders/pixelate_f.glsl", sf::Shader::Type::Fragment);
if (bRes == false) return;
ShaderPixelateF.setParameter("texture", sf::Shader::CurrentTexture);
ShaderPixelateF.setParameter("pixel_threshold", 10.0f);
//sprite to render shader with
sf::Sprite Sprite;
//main cycle
while (Window.isOpen())
{
sf::Event Event;
while (Window.pollEvent(Event))
{
if (Event.type == sf::Event::Closed || (Event.type == sf::Event::KeyPressed && Event.key.code == sf::Keyboard::Key::Escape))
{
Window.close();
}
}
RenderTexture.clear(sf::Color(0, 0, 0, 0));
RenderTexture.draw(Rect);
RenderTexture.display();
Sprite.setTexture(RenderTexture.getTexture());
Window.clear(sf::Color(0, 128, 0));//green
Window.draw(Sprite, &ShaderPixelateF);
// Window.draw(Sprite);
Window.display();
}
}
and pixelate_f.glsl is:
uniform sampler2D texture;
uniform float pixel_threshold;
void main()
{
float factor = 1.0 / (pixel_threshold + 0.001);
vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor;
gl_FragColor = texture2D(texture, pos) * gl_Color;
// gl_FragColor = vec4 (1.0, 1.0, 0.0, 1.0);//yellow
}
I'm seeing only green background.
Uncommenting line in cpp brings rect (rendering to texture works, sprite has texture properly set).
Uncommenting line in shader brings yellow box (shader works).
Where I'm doing wrong?
Thanks in advance
simps