SFML community forums

Help => Graphics => Topic started by: Odysseus on January 21, 2009, 06:48:01 am

Title: Strange Blurring
Post by: Odysseus on January 21, 2009, 06:48:01 am
This code:
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    //A simple, randomized pixel array
    uint8_t PixelData[100*100*4];
    for (int i=0; i < 100*100*4; i++)
    {
        PixelData[i] = rand();
    }

    //respective images and sprite using that array
    sf::Image Image( 100, 100, PixelData );
    sf::Sprite Sprite(Image);

    //draw the sprite to a window
    sf::RenderWindow App( sf::VideoMode(100,100,32), "SFML WIndow" );
    App.Draw(Sprite);
    App.Display();

    //Capture the window
    App.Capture().SaveToFile("window.png");

    return 0;
}


results in:
(http://www4.ncsu.edu/~gerwin/images/window.png)

when it shoud result in:
(http://www4.ncsu.edu/~gerwin/images/image.png)

 What gives?
Title: Strange Blurring
Post by: Odysseus on January 21, 2009, 07:08:02 am
With the same sprite centered in a larger window:
(http://www4.ncsu.edu/~gerwin/images/window2.png)

Looking at the image in gimp reveals that the sprite size is indeed 100x100 pixels, but for some reason, the texture has been stretched half a pixel in all directions. :?:

I also wonder if this stretching is hurting performance.
Title: Strange Blurring
Post by: Laurent on January 21, 2009, 07:52:07 am
Add this:
Code: [Select]
Image.SetSmooth(false);

Quote
I also wonder if this stretching is hurting performance.

No ;)
Title: Strange Blurring
Post by: Odysseus on January 21, 2009, 08:53:51 pm
Ok, thanks.

It still seems odd to me that it gets stretched even though it hasn't been moved or scaled or rotated or anything.  Why is that?
I mean, what's the point of the smooth filter anyway.  I don't really understand it.

And at any rate, it certainly wasn't the expected output.
Title: Strange Blurring
Post by: quasius on January 21, 2009, 09:01:19 pm
Quote from: "Odysseus"
Ok, thanks.

It still seems odd to me that it gets stretched even though it hasn't been moved or scaled or rotated or anything.  Why is that?


Because OpenGL is autmatically using sub-pixel interpolation to place your sprite.  (Remember positions are in floats).  This makes movement look smoother, but you may want to round your sprite positions the the nearest whole number when they stop.  Alternately, just disable the smoothing completely as Laurent showed.
Title: Strange Blurring
Post by: Odysseus on January 21, 2009, 09:21:30 pm
Quote from: "quasius"

Because OpenGL is autmatically using sub-pixel interpolation to place your sprite.  (Remember positions are in floats).  This makes movement look smoother, but you may want to round your sprite positions the the nearest whole number when they stop.  Alternately, just disable the smoothing completely as Laurent showed.


Ahh.  I don't really understand, but that's alright.  SetSmooth(false) will work fine.

I guess I just don't consider it intuitive.