SFML community forums

Help => Graphics => Topic started by: slotdev on January 12, 2012, 04:34:28 pm

Title: Strange lines on transparent image
Post by: slotdev on January 12, 2012, 04:34:28 pm
Hi,

I've got this wierd bug with a graphic. I display an image of a "star" which I then scale up to 300% and back to 100% over 60 frames (@30fps).

When it's over about 150% I start to see these white lines at the edge of the star image. Have a look at this graphic - white lines are highlighed in green.

(http://dl.dropbox.com/u/17968394/whitelines.jpg)

The source image is on a tile and is 112x112 in size.

Any help is much appreciated :)

Ed
Title: Strange lines on transparent image
Post by: Laurent on January 12, 2012, 04:42:05 pm
Which version of SFML?
Title: Strange lines on transparent image
Post by: slotdev on January 12, 2012, 04:56:59 pm
Sorry, forgot to say, SFML 2 from the 9th November 2011
Title: Strange lines on transparent image
Post by: Laurent on January 12, 2012, 05:35:25 pm
Have you tried to turn texture smoothing off?
Title: Strange lines on transparent image
Post by: Haikarainen on January 13, 2012, 06:35:12 am
Is the star on a tilemap? That is, you are using a subrect off a texture? In that case you have 2 options;

Dont use floats for positioning
OR, cache all the tiles into separate textures at startup, and use those textures instead.

I went with the second one. A lot of people seem to have this issue, second one works best for me.

BTW Laurent; you couldn't work out something to make this issue disappear? I've seen it a lot of times on these forums now :S  I understand if its a tough nut to crack, but might some internal caching system work, with parameters you could set through methods?
Title: Strange lines on transparent image
Post by: Laurent on January 13, 2012, 08:14:29 am
Quote
BTW Laurent; you couldn't work out something to make this issue disappear? I've seen it a lot of times on these forums now :S I understand if its a tough nut to crack, but might some internal caching system work, with parameters you could set through methods?

An internal caching system? What do you mean?
Title: Strange lines on transparent image
Post by: Haikarainen on January 13, 2012, 08:37:35 am
Quote from: "Laurent"
An internal caching system? What do you mean?


Something like sf::Texture/Sprite::CacheSubrects(bool b, sf::Uint32 limit = 48mb), and if b is true, the texture/sprite will automatically cache previously used subrects into new textures and store them, with a limit on either memorysize or texturecount, and use them when available/appropriate, instead of just drawing a part of a texture. Dont know if this would be beneficial enough to be usable (regarding performance, overhead etc), but it sure is a solution to the problem.
Title: Strange lines on transparent image
Post by: Laurent on January 13, 2012, 08:50:32 am
Quote
Something like sf::Texture/Sprite::CacheSubrects(bool b, sf::Uint32 limit = 48mb), and if b is true, the texture/sprite will automatically cache previously used subrects into new textures and store them, with a limit on either memorysize or texturecount, and use them when available/appropriate, instead of just drawing a part of a texture. Dont know if this would be beneficial enough to be usable (regarding performance, overhead etc), but it sure is a solution to the problem.

It's not a clean solution to the problem. Gathering several sprites into a single texture is an important optimization, it would make no sense to split textures internally.
Title: Strange lines on transparent image
Post by: Haikarainen on January 13, 2012, 08:56:02 am
Quote from: "Laurent"
It's not a clean solution to the problem. Gathering several sprites into a single texture is an important optimization, it would make no sense to split textures internally.


Indeed, hence the Texture /  Sprite. Anyway, it would be 1 solution even though I'm sure there are better ones. Also I find it rather important to find one for this problem, regarding the count of independent posts on this issue.
Title: Strange lines on transparent image
Post by: Laurent on January 13, 2012, 09:04:11 am
I'm afraid there's no solution. Changing the behaviour would create other issues.
Title: Strange lines on transparent image
Post by: Haikarainen on January 13, 2012, 09:19:43 am
Quote from: "Laurent"
I'm afraid there's no solution. Changing the behaviour would create other issues.


Actually it's more like adding to the behaviour, and it would be optional. Think of it as a std::vector<sf::Texture> SubTextures; in sf::Texture, wich would be unused if you dont want to use it, and if you use it, stores pixeldata contained inside a subrect of the original texture.
Title: Strange lines on transparent image
Post by: Laurent on January 13, 2012, 09:31:32 am
That would definitely not be a good solution.

But before going further, let's wait for the answer to the first question that you asked:
Quote
Is the star on a tilemap? That is, you are using a subrect off a texture?
Title: Strange lines on transparent image
Post by: slotdev on January 13, 2012, 02:58:39 pm
Yes, I'm using a sub rect from a larger texture.

I don't use floats for positioning, too :-)
Title: Strange lines on transparent image
Post by: Laurent on January 13, 2012, 03:11:57 pm
Quote
I don't use floats for positioning, too

Yeah, but if you scale it will most likely end up at float coordinates anyway ;)

A quick and dirty solution would be to add a 1-pixel margin around your sprite in the texture, the same color as the border.

What about this other question?
Quote
Have you tried to turn texture smoothing off?
Title: Strange lines on transparent image
Post by: slotdev on January 13, 2012, 03:53:36 pm
Putting a 1 pixel gap around fixed it, thanks!

Turning off texture shading isn't really an option. The user will notice the dramatic drop in quality, and it'll be reported as a "major" bug :(