• Advertisement
Sign in to follow this  

SDL surfaces won't be alpha blended!

This topic is 2999 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm writing a program in SDL, in which SDL_Surfaces are created in three different ways: 1. Loading images using IMG_Load. These images will let you alpha blend them so that they can be transparent or semitransparent. To load an image with IMG_Load, no flags have to be specified, just the file name. 2. Generating image surfaces using SDL_CreateRGBSurface. These won't let you alpha blend them, but I don't understand why. SDL_SWSURFACE is given as the flags parameter, and depth is set to 32. 3. Generating image surfaces from a text, a font and a color using TTF_RenderText_Blended. These won't let you alpha blend them either. Why?! For doing the alpha blending, SDL_SetAlpha is called and SDL_SRCALPHA is given as the flags parameter so the surfaces would be able to be transparent. alpha is set to 128 typically. Anyone who has had the same problem before and who knows how to solve it? That would be great, I'm kind of stuck here.

Share this post


Link to post
Share on other sites
Advertisement
Hidden
Are the surfaces the same pixel format as the main screen?

Try using SDL_DisplayFormatAlpha() on your surfaces and see if it helps. Otherwise I have no idea.

Share this post


Link to post
I think I have found the problem. The function SDL_SetAlpha sets the per buffer alpha value of an image, i.e. the alpha value that is associated with the image itself, not with single pixels. On the other hand, if a SDL_Buffer has an alpha channel, i.e. one alpha value for each pixel, the per buffer alpha value is ignored when blitting, which was what happened in my case.

Concerning the image loaded from file, they lost their alpha channels, since I used the function SDL_DisplayFormat to convert them to a format with faster blitting. If I would have used SDL_DisplayFormatAlpha instead as you said (which does copy the alpha channel of a buffer, in opposite to SDL_DisplayFormat which does not, in fact it doean't create an alpha channel at all), the alpha value from the loaded-from-file-buffer would have been copied into the new buffer and then the per buffer alpha value wouldn't have had any impact on the blittinf of this image either.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement