How to clear whole screen on Android

I often only render to a part of the SDL_Window on Android. For example, I only draw a 640x480 texture to the center of the SDL_Window and the rest is just blank. Sometimes, however, I need to change the location of 640x480 texture. For example, I now need to draw the 640x480 texture to the top-left corner. To do this, I first have to clear the area where the texture previously was of course.

Simply calling SDL_RenderClear() and SDL_RenderPresent() doesn’t seem to be enough for this job because of double or even multi-buffering used by the SDL renderer. So I thought let’s repeat it three times to clear all buffers, i.e. like this:

for(k = 0; k < 3; k++) {
	SDL_SetRenderDrawColor(osd->renderer, 0, 0, 0, 255);
	SDL_RenderClear(osd->renderer);
	SDL_RenderPresent(osd->renderer);
}	

However, even this doesn’t seem enough. Most of the time this clears the screen just fine but sometimes it doesn’t clear it so I was wondering if there is a better approach to make sure all buffers are cleared.

In my experience a single SDL_RenderClear/SDL_RenderPresent is sufficient to clear the entire render target, on all the platforms I support (Windows, Linux, Mac OS, Android, iOS) so I don’t know why you are getting different results. Double (or triple) buffering should not mean that you need to do it more than once, as far as I know.

Like you I often render (say) a 640x480 texture with the rest of the screen black. In my app the user can move it around (or zoom it) using touch gestures. All this works without any of the complications you describe. Incidentally I’m still using SDL 2.0.5 on Android.

Yes, you’re right. This turned out to be a problem with my code. Fixed now.

Actually, on Android just calling SDL_RenderClear/SDL_RenderPresent definitely isn’t enough. Then the last frame is still in one of the buffers and shows up every second frame. I definitely have to call SDL_RenderClear/SDL_RenderPresent twice. No idea if it’s supposed to behave like that.