SFML community forums

Help => Graphics => Topic started by: Don Andy on June 06, 2008, 03:42:28 pm

Title: Sprite blurry
Post by: Don Andy on June 06, 2008, 03:42:28 pm
Since I'm working on a rather small pixel-scale, sharpness is very important, so I already set "SetSmooth" on false for the image.

However, when moving the thing around with
Code: [Select]
if (App.GetInput().IsKeyDown(sf::Key::Left)) spr_hero.SetLeft(spr_hero.GetLeft() - 100 * ElapsedTime);

It often gets blurry and stretched, depending on how it stops. I think this has something to do with the positioning using floats. I'm not sure how to fix it, though and would appreciate any help.
Title: Sprite blurry
Post by: tgm on June 06, 2008, 04:15:25 pm
Well ,I guess there is no such thing as help
(btw.. I noticed, that the edges of the screen are more blurry than the center °_o) you can try this out, by taking a random pixelmap and sho it.
(every pixel got a random lightness between 0 and 0xff)
I wonder why? (does SFML use some kind of render to texture to display all the stuff?? -> posteffects??) P.S. there where no Post effects activated in this testcase
greetz tgm
Title: Sprite blurry
Post by: Laurent on June 06, 2008, 04:17:38 pm
Quote
I think this has something to do with the positioning using floats

In this case, using integer coordinates should solve the problem.

Quote
(btw.. I noticed, that the edges of the screen are more blurry than the center °_o) you can try this out, by taking a random pixelmap and sho it.
(every pixel got a random lightness between 0 and 0xff)

What the hell are you talking about ? :lol:
Title: Sprite blurry
Post by: Don Andy on June 06, 2008, 04:55:12 pm
Quote from: "Laurent"

In this case, using integer coordinates should solve the problem.


Uhm, yeah, that's the thing. I've gotten a bit rusty with C++ and wanted to get back into the whole thing with the help of SFML.

Do I need to rewrite the sprite class to use integers instead of floats?

It's probably something incredibly simple again <.<
Title: Sprite blurry
Post by: quasius on June 06, 2008, 07:25:34 pm
Quote from: "Don Andy"
Quote from: "Laurent"

In this case, using integer coordinates should solve the problem.


Uhm, yeah, that's the thing. I've gotten a bit rusty with C++ and wanted to get back into the whole thing with the help of SFML.

Do I need to rewrite the sprite class to use integers instead of floats?

It's probably something incredibly simple again <.<


No.  You just need to cast any position data sent to the sprite class to ints.
Title: Sprite blurry
Post by: Don Andy on June 06, 2008, 08:10:27 pm
Sorry if I sound stupid or anything, but can anybody tell me what I'd need to do with
Code: [Select]

if (Window->GetInput().IsKeyDown(sf::Key::Left)) Sprite.SetLeft(Sprite.GetLeft() - 100 * Window->GetFrameTime());


to make it work with integers? I think I've pretty much tried every possible combination of typecasts, but this isn't quite working as I want it to >.<
Title: Sprite blurry
Post by: Nexus on June 06, 2008, 09:01:26 pm
If you move your sprite (btw. isn't there a Move() function?) depending on the frametime, a constant movement is rather not propable.
Title: Sprite blurry
Post by: Don Andy on June 06, 2008, 09:24:53 pm
Well, I did it like it was described in the tutorial :/
If there is a way to keep a constant framerate and use a technique of movement that does not stretch and blur my sprite I'd gladly take it.
Title: Sprite blurry
Post by: Laurent on June 07, 2008, 01:15:38 am
Code: [Select]
Sprite.SetLeft(floor(...));
Sprite.SetTop(floor(...));
Title: Sprite blurry
Post by: Don Andy on June 07, 2008, 01:22:50 am
Aah, thanks a bunch.
Title: Sprite blurry
Post by: tgm on June 09, 2008, 07:40:53 pm
Quote

What the hell are you talking about ? :lol:


öhm.. draw a sprite with some iregular high contrast pattern (1 px checkboard for example) and you'll notice some focal blur effect in the edges of the Renderwindow...
Title: Sprite blurry
Post by: Laurent on June 10, 2008, 04:04:40 pm
Quote from: "tgm"
öhm.. draw a sprite with some iregular high contrast pattern (1 px checkboard for example) and you'll notice some focal blur effect in the edges of the Renderwindow...

Do you have a perfect 1:1 pixel match between your window and your 2D world ? If not, the blur effect is not surprising.
Title: Sprite blurry
Post by: tgm on June 10, 2008, 05:21:11 pm
yeah.. I think so..
simply using a normal rendering window, and drawing a 800x600 (for example) sprite without changing anything about scale etc..
Title: Sprite blurry
Post by: Laurent on June 11, 2008, 02:51:30 am
Ok, I'll do some tests.