http://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlsetalpha.html describes blitting for each possible pixel format combination.
When alpha blending is performed, standard formula is SRC_COLOUR * SRC_ALPHA + DST_COLOUR * (1 - SRC_ALPHA)
. Destination alpha isn't used in here.
If alpha blending is enabled, and SRCALPHA flag is enabled for source surface, source alpha is used to re-calculate (blend) updated destination colours, but alpha channel of destination is left untouched. Next time this 'dst' used as source of blitting, its alpha would be used.
To avoid your problem, there are several possible ways:
- Disable SRCALPHA for source surface (you already tried that)
- Disable SRCALPHA for destination surface, so it will not be blended with screen. It does not affect initial blit, but does affect next one, when your 'target' (or 'copy') used as source to blit on screen.
- Fill destination surface with opaque white. It does, however, affect blitting, on [partially]-transparent parts of source (alpha blending with white and with black produces different results).
- Manually copy pixels. If pixel format and surface dimensions match, mere
memcpy
would be enough. This will overwrite contents of destination, not blend it. It also would be noticeably faster than blend. If dimensions do not match - depending onpitch
parameter you probably would need number_of_rowsmemcpy
's. If pixel formats do not match - copying is problematic, you need to decode each pixel from source pixel format and encode it to destination pixel format. - Use SDL_ConvertSurface (e.g.
SDL_ConvertSurface(source, source->format, 0)
. It will create new surface with the same contents. I think this way is preferred. Don't forget to free new surface later. - Use SDL_DisplayFormatAlpha if you use SDL 1.2. This is almost the same as
SDL_ConvertSurface
, but converts surface to display format, not source surface's one. It is no longer available in SDL2.
Also note that (4), (5) and (6) are only ways I see that allows you to keep source alpha. All blitting operations discarding source alpha, leaving destination with its own alpha values - as blitting never updates destination alpha.