Hey guys,
I'm currently trying to get into shader programming a bit. However, I encounter a problem which doesn't appear to make any sense to me.
The shader I'm using is the following:
uniform sampler2D tex;
void main()
{
vec4 sum = vec4(0.0);
vec2 offx = vec2(1.0, 0.0);
vec2 offy = vec2(0.0, 1.0);
sum += texture2D(tex, gl_TexCoord[0].xy - offx - offy);
sum += texture2D(tex, gl_TexCoord[0].xy - offy);
sum += texture2D(tex, gl_TexCoord[0].xy + offx - offy);
sum += texture2D(tex, gl_TexCoord[0].xy - offx);
sum += texture2D(tex, gl_TexCoord[0].xy);
sum += texture2D(tex, gl_TexCoord[0].xy + offx);
sum += texture2D(tex, gl_TexCoord[0].xy + offx + offy);
sum += texture2D(tex, gl_TexCoord[0].xy + offy);
sum += texture2D(tex, gl_TexCoord[0].xy - offx + offy);
gl_FragColor = (sum / 9.0);
}
It's a plain, simple box filter. I can't spot any mistakes in it, which might be owed to the fact that I'm lacking any experience with shader programming.
A minimal example for the C++-code is:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow win(sf::VideoMode(800, 600), "Shader");
sf::Image image;
image.LoadFromFile("tulips.jpg");
sf::Shader postEffect;
postEffect.LoadFromFile("blur.sfx");
sf::RenderImage renderImage;
renderImage.Create(win.GetWidth(), win.GetHeight());
renderImage.Clear();
renderImage.Draw(sf::Sprite(image));
renderImage.Display();
sf::Sprite screen(renderImage.GetImage());
while (win.IsOpened()) {
sf::Event e;
if (win.GetEvent(e)) {
if (e.Type == sf::Event::KeyPressed && e.Key.Code == sf::Key::Escape) {
win.Close();
}
}
win.Clear();
win.Draw(screen, postEffect);
win.Display();
}
}
Yet again, I can't see a problem with it. I tried to stick as close to the examples given here (
http://www.sfml-dev.org/forum/viewtopic.php?p=11699) as I could. Nevertheless other approaches elicit just the same problem, namely:
I'm using the SFML2.0 binaries for Visual Studio 2010, someone uploaded them here in the forum a while ago. Operating system is Windows 7.
While writing this, it occurs to me that the graphics chip of my notebook is merely an Intel HD Graphics onboard-chip, but that should not pose a problem, I expect.
I hope some of you are able to spot the certainly quite obvious error. I can't, however, so thanks in advance.
Regards,
Debilo