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

Author Topic: Strange lines on transparent image  (Read 4155 times)

0 Members and 1 Guest are viewing this topic.

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Strange lines on transparent image
« 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.



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

Any help is much appreciated :)

Ed
SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Strange lines on transparent image
« Reply #1 on: January 12, 2012, 04:42:05 pm »
Which version of SFML?
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Strange lines on transparent image
« Reply #2 on: January 12, 2012, 04:56:59 pm »
Sorry, forgot to say, SFML 2 from the 9th November 2011
SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Strange lines on transparent image
« Reply #3 on: January 12, 2012, 05:35:25 pm »
Have you tried to turn texture smoothing off?
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Strange lines on transparent image
« Reply #4 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Strange lines on transparent image
« Reply #5 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?
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Strange lines on transparent image
« Reply #6 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Strange lines on transparent image
« Reply #7 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.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Strange lines on transparent image
« Reply #8 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Strange lines on transparent image
« Reply #9 on: January 13, 2012, 09:04:11 am »
I'm afraid there's no solution. Changing the behaviour would create other issues.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Strange lines on transparent image
« Reply #10 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Strange lines on transparent image
« Reply #11 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?
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Strange lines on transparent image
« Reply #12 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 :-)
SFML 2.1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Strange lines on transparent image
« Reply #13 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?
Laurent Gomila - SFML developer

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Strange lines on transparent image
« Reply #14 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 :(
SFML 2.1