Thursday, May 24, 2018

rendering - 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.



Answer



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



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...