In the SDL2 documentation it is mentioned that :
You are strongly encouraged to call SDL_RenderClear() to initialize the backbuffer before starting each new frame's drawing, even if you plan to overwrite every pixel.
What is the reason behind that? Isn't it just a useless call to fill the screen one particular color when you know you're going to overwrite it anyway?
If you're sure that you will draw over every pixel with a fully nontransparent color you don't need to use SDL_RenderClear().
SDL_RenderClear() is for when you you have a backround color in your frame thats actual visible.
You don't need to call SDL_RenderClear()
in every frame if you are updating every pixel. You can even make some nice effects by using semi-transparent pixels (e.g, "motion blur" by painting a black semi-transparent rectangle before painting another frame).
If this is just your own code, yeah, it might seem useless, but you knever know once your code is in the hands of someone else. They might use different images, things that are transparent and they're going to have a hard time figuring out why everything is repeated in the screen.
Thats one good reason to be encouraged to clear the screen. You are not required to do so. Also, its worth noting that clearing the screen with a color is different than filling the screen with a color by painting every pixel (and a lot faster), thus, your performance lost is neglible compared to the potential future headache.
You can check the RenderClear
code for every platform and see how it does different things to do what you said (fill the screen with a color), but with clear method rather than paint method:
You can see that the only implementation of SDL_RenderClear
that actually fills the screen is the SW_RenderClear
one, but other than that, there is no harm in clearing the screen, but no obligation either. SDL works just fine without it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With