Search code examples
c++linuxsdlsdl-1.2

SDL: Make existing surface transparent / delete all pixel data


i have a transparent surface in SDL, this surface contains pixel data. I now need to "clear" this surface.

Is there a way to clear the surface, so its completely transparent (so i can draw new stuff on that?). The only ways i found was to create a whole new surface, but i would like to avoid that for several reasons.


Solution

  • What version of SDL are you using (1.2 or 2.0).

    You can "clean" the surface by setting all the pixels to a certain color (see memset and the pixels member from SDL_Surface). But you don't need to make it transparent in order to draw over it. If you blit another surface on it, all the pixels should change their color. Can you provide os with the code?