SDL_RenderClear not clearing entire render target

I’m using render to texture to render a little animated scene to a texture each frame. What I’m doing is:

Code:
SDL_SetRenderTarget(main_window.renderer,texture);
SDL_SetRenderDrawColor(main_window.renderer,0,0,0,0);
SDL_RenderClear(main_window.renderer);

… …

SDL_SetRenderTarget(main_window.renderer,NULL);

… …

This texture is to be rendered in my game world later in the frame, and needs a transparent background. It is not the same size (or aspect ratio) as the window. The above code works great, with one caveat: only about 3/4s of the texture gets cleared on calling SDL_RenderClear. The bottom 1/4 or so never clears, and so the various animations eventually cover the whole section in solid color.

The size of the window is 1280x720. The size of the texture is 1024x1024. I’ve noticed that if I create the texture with a size of 1280x720 instead, the clearing works perfectly (but of course my texture is the wrong size which is unacceptable).

This would seem to have something to do, then, with the difference in size between the window and texture. However, the docs for SDL_RenderClear suggest that size shouldn’t matter. In fact, they explicitly state “This function clears the entire rendering target, ignoring the viewport.” As far as I can tell that simply is not happening. Am I missing something obvious or is this a bug?

This is being tested in Windows 7 Professional 64-bit.

I’ve posted a video showing what I’m talking about here: http://www.youtube.com/watch?v=v7Np5S3Bgj0

The game is a 2D top-down affair, and the animated texture I’m making is falling raindrops. The game world is divided into “chunks” of 1024x1024 pixels, and weather occurs at this resolution, so my 1024x1024 rain texture is rendered over any chunk in which it is raining. As you can see, the bottom section of the texture quickly fills with raindrop color and is never cleared.

I just did some more tests, and ‘SDL_RenderFillRect(main_window.renderer,NULL)’ DOES fill the entire texture with color. Unfortunately, you cannot erase color, only cover it with new color, so this won’t work for me.

I just thought to try ‘SDL_SetHint(SDL_HINT_RENDER_DRIVER,“opengl”)’ as SDL was defaulting to direct3d. That fixed the problem! So that narrows it down a bit more if someone wants to try to figure out what’s going on here.

Try:

SDL_SetRenderTarget(main_window.renderer,texture);
SDL_SetRenderDrawColor(main_window.renderer,0,0,0,255);
SDL_RenderClear(main_window.renderer);

See if that does what you want.

JosephOn Thu, Oct 17, 2013 at 11:35:33PM +0000, Dark_Oppressor wrote:

I’m using render to texture to render a little animated scene to a texture each frame. What I’m doing is:

Code:
SDL_SetRenderTarget(main_window.renderer,texture);
SDL_SetRenderDrawColor(main_window.renderer,0,0,0,0);
SDL_RenderClear(main_window.renderer);

… …

SDL_SetRenderTarget(main_window.renderer,NULL);

… …

This texture is to be rendered in my game world later in the frame, and needs a transparent background. It is not the same size (or aspect ratio) as the window. The above code works great, with one caveat: only about 3/4s of the texture gets cleared on calling SDL_RenderClear. The bottom 1/4 or so never clears, and so the various animations eventually cover the whole section in solid color.

The size of the window is 1280x720. The size of the texture is 1024x1024. I’ve noticed that if I create the texture with a size of 1280x720 instead, the clearing works perfectly (but of course my texture is the wrong size which is unacceptable).

This would seem to have something to do, then, with the difference in size between the window and texture. However, the docs for SDL_RenderClear suggest that size shouldn’t matter. In fact, they explicitly state “This function clears the entire rendering target, ignoring the viewport.” As far as I can tell that simply is not happening. Am I missing something obvious or is this a bug?

This is being tested in Windows 7 Professional 64-bit.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Joseph Carter wrote:

Try:

SDL_SetRenderTarget(main_window.renderer,texture);
SDL_SetRenderDrawColor(main_window.renderer,0,0,0,255);
SDL_RenderClear(main_window.renderer);

See if that does what you want.

Joseph

I’m using render to texture to render a little animated scene to a texture each frame. What I’m doing is:

Code:
SDL_SetRenderTarget(main_window.renderer,texture);
SDL_SetRenderDrawColor(main_window.renderer,0,0,0,0);
SDL_RenderClear(main_window.renderer);

… …

SDL_SetRenderTarget(main_window.renderer,NULL);

… …

This texture is to be rendered in my game world later in the frame, and needs a transparent background. It is not the same size (or aspect ratio) as the window. The above code works great, with one caveat: only about 3/4s of the texture gets cleared on calling SDL_RenderClear. The bottom 1/4 or so never clears, and so the various animations eventually cover the whole section in solid color.

The size of the window is 1280x720. The size of the texture is 1024x1024. I’ve noticed that if I create the texture with a size of 1280x720 instead, the clearing works perfectly (but of course my texture is the wrong size which is unacceptable).

This would seem to have something to do, then, with the difference in size between the window and texture. However, the docs for SDL_RenderClear suggest that size shouldn’t matter. In fact, they explicitly state “This function clears the entire rendering target, ignoring the viewport.” As far as I can tell that simply is not happening. Am I missing something obvious or is this a bug?

This is being tested in Windows 7 Professional 64-bit.

That won’t help in my situation because I need the texture to be cleared to transparency. I did try that though, and it doesn’t help. The top 3/4s of the texture are cleared to black and the bottom remains uncleared.

I’ve just reported both this and another (apparently related) issue I’ve been having. Both of them were solved by switching to the opengl render driver.
You can see them here:
https://bugzilla.libsdl.org/show_bug.cgi?id=2160
https://bugzilla.libsdl.org/show_bug.cgi?id=2162> On Thu, Oct 17, 2013 at 11:35:33PM +0000, Dark_Oppressor wrote: