I have a SDL_Renderer
in SDL2 that I use both to render textures on screen and to render textures on textures, my problem is that when I render to texture the renderer may have some content in it which needs to be drawn, but if it's empty and I call SDL_RenderPresent()
on it the screen flickers. So how can I check if there's something drawn inside the renderer?
\$\begingroup\$
\$\endgroup\$
1
-
\$\begingroup\$ Track it separately. \$\endgroup\$– ratchet freakCommented Nov 9, 2015 at 13:14
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
Ok, so from what I understood, when you are rendering to a texture there's no need to flush the renderer before, not even after; that's why there isn't such function to check if the renderer is empty or not.
So the steps are these:
// This draws inside the renderer's buffer
SDL_RenderCopy(renderer, texture, source, bounds);
// This switches to rendering on texture
SDL_SetRenderTarget(renderer, target_texture);
// Apparently this is enough to draw on the texture (so there's no buffer I guess?)
SDL_RenderCopy(renderer, texture2, source, bounds);
// This switches to rendering on renderer buffer
SDL_SetRenderTarget(renderer, NULL);
// This flushes the renderer buffer (so only the SDL_RenderCopy() before rendering on texture)
SDL_RenderPresent(renderer);
See my other question for this.