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

Author Topic: Using View and TextureRect: pixel line glitch  (Read 1722 times)

0 Members and 1 Guest are viewing this topic.

Daerst

  • Newbie
  • *
  • Posts: 12
    • View Profile
Using View and TextureRect: pixel line glitch
« on: May 08, 2014, 09:52:14 pm »
Hello,

I know this problem isn't new. I searched, found workarounds, and they didn't work for me or at least I don't fully understand the topic and would like to know more. I hope you can help me out here.

I have animated sprites in a game, using the SetTextureRect() function1. The spritesheets have no gaps between the single images. The game uses a view to resize an area of 640x480 units to the full screen while keeping the aspect ratio. Example: for 16:9, the 640x480 area is resized to 1440x1080 and has black borders to the left and right. The example sprite below is also scaled (uniformly by 3).

This is what I get:


Notice the black stripes above and to the left? This is a part of the next image, and I don't like it. In this thread, Laurent said that it's intended behaviour, but I can't quite understand the intention.

What I tried:
  • Rounding the coords to integral numbers before drawing
  • The above, subtracting 0.375f in each direction (is this still valid in SFML 2.1?)
  • The above, but subtracting 0.375f*scale
  • Creating a gap between the images in the spritesheet of course solves the problem, but does not seem like the most elegant solution...

Could someone explain to me why this is happening, and if there is a workaround?
If you want to see the game, and the error, in action, you're welcome to do so :)

Thanks a lot,
David



1Actually I'm using SFML.Net with C#, so it's TextureRect's setter.

Daerst

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Using View and TextureRect: pixel line glitch
« Reply #1 on: May 18, 2014, 01:19:20 pm »
After lots of research, I identified two methods:

One, on a low level apply an absolute offset of 0.375. This was kinda hard for me, because of the whole C# / C++ port thingy.

Second, insert padding between sprites. If they aren't tiled, insert transparent pixels. If the sprites should tile, insert a 1px line of the other side of the tile.

Usin the latter approach, I just had to modify a couple of lines of code and all my graphics (which indeed was kinda fiddly, but worthwhile). Hope this will save you some headaches :)

Rhimlock

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: Using View and TextureRect: pixel line glitch
« Reply #2 on: May 20, 2014, 04:41:42 pm »
Your texture is smoothed.

Disable it by using
tex.setSmooth(false);