Jump to content
  • Advertisement
Sign in to follow this  

C++ [SDL2] Trying to fix Bleeding pixel with Backbuffer, but resulted in blurry graphic

Recommended Posts

Posted (edited)

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 1
Without back buffer https://imgur.com/bAW4Xf2 1

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

Edited by Sunsharior

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!