I need to clear a streaming texture before I draw into it on the next frame, because only a part is updated, and it's random enough that I can't predict which part will be clear.

I don't want to reinitialize it every time, or rewrite the whole texture each time.

Here is the code I tried, but this fails every time, since the texture is in streaming mode.

SDL_Texture* StreamingTexture = SDL_CreateTexture(render, SDL_PIXELFORMAT_RGBA8888, 
        SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);

SDL_SetRenderTarget(render, StreamingTexture);
SDL_SetRenderDrawColor(render, 0, 0, 0, 0);
  • \$\begingroup\$ Why are you using a streaming texture? \$\endgroup\$ – Tyyppi_77 Oct 11 '16 at 4:44
  • \$\begingroup\$ This feels like an XY problem. What are you actually trying to do here? \$\endgroup\$ – Tyyppi_77 Oct 11 '16 at 18:10
  • \$\begingroup\$ nah i got it :D \$\endgroup\$ – The guy Oct 11 '16 at 21:08
  • \$\begingroup\$ @Tyyppi_77 Essentially i need to write just few pixels, and i need to clear the texture, otherwise it makes this ghost effect. \$\endgroup\$ – The guy Oct 11 '16 at 21:15

You just need to use SDL_FillRect:

SDLX_TextureLockSurface(Texture, Surface);
SDL_FillRect(Surface,NULL,SDLX_RGBAtoPixel(0,0,0,0)); // <<-- this is what clears entire texture 
SDLX_TextureUnlock(Texture); //LOOOOOCK !!!!!
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.