Jump to content
  • Advertisement
Sign in to follow this  
andyZER0

OpenGL SDL Color Key equivalence in OpenGL blending

This topic is 5042 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

I'm rendering regular .bmp texture on quads to make sprites. In SDL, you simply have to use the SDL_SetColorKey function to make a certain color in the graphic become transparent (preferably ff00ff/violet). I'm trying to achieve this effect in OpenGL using blending. I've been using glBlendFunc(GL_SRC_ALPHA, GL_ONE) to make anything purely black in the texture transparent. But, I'm not quite getting the effect I want. Is there a way to achieve SDL Color Key like transparency in OpenGL blending? Or would I have to use something like masking? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
one method is that on load you add an alpha channel to the image setting it to full alpha where you want to see the color and zero for the transparent color, then use the alpha blending function you've got there to blend it together (maybe with alpha test, with the threshold set to zero or very low so that they dont even get to the blending stage and are just rejected)

Share this post


Link to post
Share on other sites
The alpha channel is just part of the texture. When using glTexImage2D for the texture you have to specify 4 components and a format of GL_RGBA so it can load the alpha channel correctly (and of course the raw pixel data you supply it with must also be of the correct format). Once you have a texture with an alpha channel use alpha testing (look up glAlphaFunc for more info on it) so that when rendering the texture fragments with alpha values lower than a certain threshold get discarded. Thus instead of putting say pink where you want transparent areas you'd instead have an alpha of 0.0, and an alpha of 1.0 (i.e. 255 as an unsigned byte value) where you wanted the texture to be opaque.

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!