Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Strange Blurring  (Read 2875 times)

0 Members and 1 Guest are viewing this topic.

Odysseus

  • Newbie
  • *
  • Posts: 4
    • View Profile
Strange Blurring
« 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:


when it shoud result in:


 What gives?

Odysseus

  • Newbie
  • *
  • Posts: 4
    • View Profile
Strange Blurring
« Reply #1 on: January 21, 2009, 07:08:02 am »
With the same sprite centered in a larger window:


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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Strange Blurring
« Reply #2 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 ;)
Laurent Gomila - SFML developer

Odysseus

  • Newbie
  • *
  • Posts: 4
    • View Profile
Strange Blurring
« Reply #3 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.

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Strange Blurring
« Reply #4 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.

Odysseus

  • Newbie
  • *
  • Posts: 4
    • View Profile
Strange Blurring
« Reply #5 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.