# SDL2 Textures bleeding / 1px border around tile maps - SDL_RenderCopyEx taking integer arguments

https://forums.libsdl.org/viewtopic.php?t=9486 This post gives a good indication of my question.

Basically if you set SDL2 logicalScale or otherwise and render textures at native window resolution they appear fine. However, with tile maps if you resize the window in anyway, you get a bleed where an integer rounding issue creates a 1px border around certain tiles.

Is my only option to create a 1px border around all my images to stop this bleed / rounding error? Or a semi-transparent border with the main color. What are my options? Is this solved in any of the latest SDL2.X.Y ?

EDIT: A simpler method I have used is reducing my images from 64x64px to 62x62px in SDL2 (not the actual sprite) and using it's own sprite as a 1px border, and using Render Scaling to scale up that 1px, which stops bleed. It reduces the quality on background images ever so slightly, but it requires no tweaking of any code or sprites... but again wondering if there's a more elegant solution.

This is definitely a short-coming of the renderer implementation. There are however a few things you could try:

1. SDL_RenderSetIntegerScale

This restricts the logical viewport to scale with integer values, which should remove rounding errors from the rendering.

2. One option, which I used myself after giving up on this issue, is to roll your own rendering code. It's not that difficult, basically you just drop the logical scale from your code and instead calculate a scale factor yourself, and then use that to scale your destination rectangle before rendering. Of course, with this, you might have to handle some stuff a little more complicated (screenspace vs worldspace), but as a bonus, you can easily enabled or disable the scaling, and so you can for an example render your UI at full resolution, but scale the game world 4x the original size.

• 1. This function is available since SDL 2.0.5. That's super awesome 2. I thought of this, may try it out in the future Thank you for the assistance – jake May 27 '17 at 12:49
• Just tried out SDL_RenderSetIntegerScale seems to not really do what I want, as it just doesn't change resolutions if there is bleeding, rather than just distorting it slightly. Guess I'll have to stick to scaling images up a tad, and reducing their size by 1px – jake May 27 '17 at 13:32

The option I went with is to use an SDL_Texture as a Render Buffer created with SDL_TEXTUREACCESS_TARGET (But still using a logical screen size in the renderer). The Renderer can copy any number of textures onto the buffer, then after all rendering is done, change render target to the window and copy the buffer to the window.

An example can be found here: https://gist.github.com/Twinklebear/8265888