SFML community forums
Help => Graphics => Topic started by: Odysseus on January 21, 2009, 06:48:01 am
-
This code:
#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?
-
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.
-
Add this:
Image.SetSmooth(false);
I also wonder if this stretching is hurting performance.
No ;)
-
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.
-
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.
-
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.