Trying to fix Bleeding pixel with Backbuffer, but resulted in blurry graphic


#1

Hello everyone.

I am working on a project using SDL2 and so far its been pretty straightforward. However, I’ve come to a problem i cannot solve, so I’ve come here for your opinion.

You see, i had a problem with “bleeding pixel” a while back, and i successfully resolved it by using SDL_RenderSetIntegerScale. While this worked, it had the drawback that i could not make my SDL2 project full screen without having letterbox, both vertically and horizontally.

I was content for a while, but now i would like to actually be able to go full screen without the letterboxing. I’ve read that i can use a backbuffer, change my render target with SDL_SetRenderTarget, renderCopy to the back buffer then switch and renderpresent. It work flawlessly for solving the bleeding pixel issue and removing the letterboxing. Obviousbly, my sprite are rendered stretched, but this is not the issue at hand.

MY current issue is that i noticed all the sprite i render scalling down look very blurry.
With back buffer https://imgur.com/8jglxNZ
Without back buffer https://imgur.com/bAW4Xf2

As you can see, my font is rendered extremely blurry with the back buffer. No other sprites are rendered blurry unless it is scaled down.

I’ve tried for the last three days to fix the issue, but alas, i’ve failed and now i’m turning to you. If someone have experience with this problem, i’ll be more than happy to listen.

More information:
I do use
SDL_RenderSetLogicalSize,
SDL_RenderSetScale, which is twice my logical size,
SDL_RenderSetIntegerScale (false when using back buffer, true otherwise)
I use SDL_RenderCopyEx for my rendering
SDL_RenderPresent for my rendering
For reference, this was the bleeding pxiel issue here https: // imgur .com/KkWtfoC

Thank you for your time.


#2

I solved this error. Here is the solution.

When creating the buffer, create it with the current renderscale. In my case, my render scale was 2.
buffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, screenwidth * renderScaleX, screenheight * renderScaleY);

Then when switching buffer, Reset the render scale. You will need to do this every frame.

SDL_SetRenderTarget(renderer, buffer );

SDL_RenderSetScale(renderer, renderScaleX, renderScaleY);

The reason for this is that, in my case, everytime i switched buffer, the RenderScale got changed to some weird value like 1.024.
This is what resulted in the scaled down sprite being rendered all blurry.

I hope this will help people who google stuff in the futur.

Oh and by the way, this fix both solve my bleeding pixel issue and the blurry issue.