Jump to content
  • Advertisement
Sign in to follow this  

How to check if a SDL_Buffer has an alpha channel?

This topic is 3271 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! How can you check whether a true color SDL_Buffer (not 8 bits per pixel) has an alpha channel or not? SDL has to know this itself when it blits a buffer to another buffer, so it must be possible to check it some how. For example, an image that is loaded from a png file into a SDL_Buffer, should afterwards be converted to a SDL_Buffer with the same pixel format as the screen buffer, for faster blitting. This can be done with SDL_DisplayFormat for example, but then the alpha channel won't be copied, and the per buffer alpha value will be used instead when blitting the image if it has alpha-blending enabled. If you use SDL_DisplayFormatAlpha instead, the alpha channel will be copied, and then that will be used as alpha instead of the per buffer alpha value. The thing is that blitting an image with an alpha channel and alpha-blending enabled on another buffer with the same settings is kind of buggy. Apparently the alpha channel of the destination image is replaced by the alpha channel of the source image, on the part that is being blitted on. So a fully opaque image can become transparent or semi-transparent after blitting. That is why I'm writing my own blit function, but then I need to know if an image has an alpha channel or not, so I know from where the alpha value should be taken.

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!