We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2883 - Sprite sheet rectangle bleed
Summary: Sprite sheet rectangle bleed
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.3
Hardware: x86_64 Windows 7
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-18 17:15 UTC by MikeyPro
Modified: 2015-02-19 18:59 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description MikeyPro 2015-02-18 17:15:43 UTC
Animated sprite frame rectangles will sometimes "bleed" or "overlap" into other frames due to the open gl renderer's RenderCopy function using floats instead of integers to calculate source rectangles for textures. Since no users can actually send floats to RenderCopy (on the outside, programmers can only use SDL_Rect which is int only) I would suggest to lock in using integers only and use the integer forms of the opengl functions to draw the texture. I'm not sure how the other renderers work, some of them may also need fixing.

I checked the latest online sources and this is where the problem is coded in:
Source file: SDL_render_gl.c 
Starting around line: 1209

NOTE: For my testing, this only affects me in windowed mode on windows 7. In fullscreen, there is no bleed, but there is still potential for it to happen with the right settings. This comes down to the pixel ratio being a perfect fit in fullscreen, but not windowed. I tested windowed in an 800x600 window on a 1768x996 desktop and always use desktop resolution in fullscreen with logical resolution of 320x240 for both modes. 

This is also discussed in the forum topic https://forums.libsdl.org/viewtopic.php?t=10945
Comment 1 MikeyPro 2015-02-19 15:53:24 UTC
I did some more testing, when I use SDL_Hint to set linear quality, almost all textures end up bleeding in both windowed mode and fullscreen mode using the opengl renderer.
Comment 2 Alex Szpakowski 2015-02-19 17:44:54 UTC
This isn't really something that's caused by SDL's code. Rotating a sprite will still cause texture bleeding if the texels next to the sprite in the texture atlas are different, due to the way GPUs rasterize geometry and sample from textures.

The best way to prevent sprite bleeding in texture atlases is to add a 1px extrusion to each sprite in the texture atlas (i.e. duplicate the pixels at the edges of each sprite.)

Sprite packing tools such as TexturePacker and ShoeBox can do this for you automatically.

http://www.matim-dev.com/texture-packer---get-rid-of-sprite-artefacts.html
https://www.codeandweb.com/texturepacker/documentation#sprites

If you use raw OpenGL and you target OpenGL 3+ or OpenGL ES 3+, you could use Array Textures instead of texture atlases. SDL_Render wouldn't be able to do that internally because you feed individual sprites as layers to Array Textures, rather than using a large atlas texture.
Comment 3 MikeyPro 2015-02-19 18:59:03 UTC
I want to argue, but I wont because I'm wrong. I am really pissed this is how it must be done due to inaccuracies in underlying systems. I am setting this bug as resolved invalid. Thank you for the reply, Alex.