SFML community forums
Help => Graphics => Topic started by: Voroz on March 20, 2010, 12:31:20 pm
-
Hi. I have a problem with scaling. It keeps scaling back and forth, causing blurry edges. This is causing the same edges as i had when the character wouldn't stop moving proerly, so he moved back and forth between 2 frames close to eachother, causing this blurry edge look. Now he does it, but because of scaling.
I know this because it works without scaling, and the SetCenter location is not blurry, so it's caused by the scaling.
The question is. Why does it do that? I will post zoomed in pics to show you what i mean.
This is how it looks with scaling:
(http://img208.imageshack.us/img208/6651/blurr.png)
This is where i scale and draw char location:
//Set Scale
Character.SetScale(character.y / screenHeight, character.y / screenHeight);
//From struct to drawable
Character.SetPosition(character.x, character.y);
Anyone have any ideas what it could be?
-
This happens because the pixels of the image does not fit the pixels on screen, exactly. So if a screen pixel could be either the spite- or background-color, it will be up to SFML and the system it relies on to decide what color a pixel will be.
Your best bet is to make sure the pixels of your sprite fits the pixels on screen at the current zoom level, before you draw them. Does that make sense?
Laurent - It would be really cool if this could be done by SFML. Maybe in SFML 2?
-
ehm ok.. and how would i make sure that they do that?
-
I haven't quite figured it out yet, sorry. So if someone has a solid solution, I would be interested to see it, too.
I can tell you that it involves scaling the sprite to fit the screen pixels, though.
I do, however, use something slightly similar in my current project, to draw lines. So I could show you that, if you are interested, but I don't think it can be directly translated, though, and maybe it is a little messy, too...
EDIT:
Argh, I see now that you were actually talking about scaling your sprites, and I had somehow gotten it into my head that you meant zooming the view...
In that case, just make sure that you always scale to a whole number.
So if you have a float scale variable, then you just do:const float &flooredScale = floor( scale );
sprite.Scale( flooredScale, flooredScale );
Or maybe more correctly:const float &roundedScale = floor( scale + .5f );
sprite.Scale( roundedScale, roundedScale );
-
Laurent - It would be really cool if this could be done by SFML. Maybe in SFML 2?
Automatic rounding of coordinates was done in SFML 2, but I had to remove it because it created other problems that were impossible to solve.
Therefore, you still have to properly align your drawables in SFML to get pixel perfect rendering.
-
does this mean that the scaling has to be done so the resulting width / height becomes an integer?
-
Yes.
-
Ok this is very weird. I no longer get this issue. in older builds i still get it, although i no longer have the source code of these builds. It's just very weird because i haven't changed anything that should have anything to do with the issue. I have been adding some trees, and that's mostly it..
edit: hah. stripped the code alot and still no problem, so i started checking settings. I had changed anti-aliasing from 2 to 0, and that was my problem, so i don't know what you are all going on about pixels matching etc ^^.
To clarify. 2 aa was bad, 0 is good.
-
Laurent - It would be really cool if this could be done by SFML. Maybe in SFML 2?
Automatic rounding of coordinates was done in SFML 2, but I had to remove it because it created other problems that were impossible to solve.
Therefore, you still have to properly align your drawables in SFML to get pixel perfect rendering.
I see. Then I it would be really helpful if the tutorial showed how to do that.
By the way, I have been skimming the tutorial for 1.6, and it looks like it has a lot of new information. Very cool! :D
-
I see. Then I it would be really helpful if the tutorial showed how to do that
It would be helpful to have tutorials for SFML 2 ;)
By the way, I have been skimming the tutorial for 1.6, and it looks like it has a lot of new information
Really? I didn't know :lol:
-
By the way, I have been skimming the tutorial for 1.6, and it looks like it has a lot of new information
Really? I didn't know :lol:
Haha - I take it back - I must have been seeing things, because now they look exactly the same. Too much coffee, I guess :lol: