Lost transparency in SDL surfaces drawn manually
- by Christian Ivicevic
I want to create SDL_Surface objects for each layer of my 2d tile-based map so that I have to render only one surface per layer rather than too many tiles. With normal tiles which do not have transparent areas this works well, however I am not able to create a SDL_Surface with transparent pixels everywhere to be able to draw some tiles on specific parts which should be visible (I do NOT want the whole surface to appear with a specific opacity - I want to create overlaying tiles where one can look through).
Currently I am creating my layers like this to draw with SDL_BlitSurface on them:
SDL_Surface* layer =
SDL_CreateRGBSurface(
SDL_HWSURFACE | SDL_SRCALPHA,
layerWidth, layerHeight, 32, 0, 0, 0, 0);
If you have a look at this screenshot I have provided here
you can see that the bottom layer with no transparent parts gets rendered correctly. However the overlay with the tree tile (which is transparent in the top left corner) is drawn own its own surface which is black and not transparent as expected. The expected result (concerning the transparency) can be seen here
Can anyone explain me how to handle surfaces which are actually transparent rather than drawing all my overlay tiles separately?