Jump to content
  • Advertisement
Sign in to follow this  
KevArnold

OpenGL BMP bleed color

This topic is 3359 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 have BMPs which use the color 255, 0, 255 to specify that the pixel should actually be fully transparent. Is there a way to do this in OpenGL when rendering the texture? I realize that before I load it I could search for the bleed color and set the alpha channel to transparent but for a variety of reasons that solution is not the best for my current problem.

Share this post


Link to post
Share on other sites
Advertisement
You can do it in a pixel shader if you like. Really, though, doing the preprocessing on texture loading is the better solution. What are the "variety of reasons" that make you think it isn't best?

Share this post


Link to post
Share on other sites
That's fine. The time to process a color key into an alpha channel is trivial, so it would be fine to redo it every time the texture changed.

Share this post


Link to post
Share on other sites
@KevArnold: Perhaps you can give us more details as to your purposes so we can help better?

The easiest way (though this is arguable) is to check the color of each pixel as you load the image as you stated, but it has the drawback of causing color bleeding problems. The transparent color will tend to blend into the nearest opaque color along the edges where transparency meets opaqueness. There are a number of solutions to this involving the way you generate your textures, different settings for alphafunc, or using a file format with an integrated alpha channel (combined with some other tricks).

Share this post


Link to post
Share on other sites
I am writing a UI that is defined in XML. One part of the XML defines all the resources that are used the other part defines the layout. In the layout a bleed color is specified. This means that multiple objects can use the same image but use different bleed colors.

I should have said above that I am using OGL ES 1.1 so it is a fixed pipe line only.

Share this post


Link to post
Share on other sites
Quote:
Original post by KevArnold
I am writing a UI that is defined in XML. One part of the XML defines all the resources that are used the other part defines the layout. In the layout a bleed color is specified. This means that multiple objects can use the same image but use different bleed colors.

I'm a little confused. Under what circumstances would you want to use the same image but a different color key?

Share this post


Link to post
Share on other sites
Just adding my experience with this which has been limited but hopefully worth while in this case. I also use the RGBA color 255,0,255,0 as my color key in many images and had some weird halos when using alpha blending, scaling and rotation.

I found that prior to loading the texture (while the raw pixels were in memory) I could change the pixels which matched my color key to 0,0,0,0 which still left the halos but not nearly as noticeable since they were black. The original image on disk was never changed mainly because they are mostly 24 bit BMP files that I can easily edit with MS Paint or Paint .NET and black is a pretty popular color in most of my sprites and I don't want it all to be transparent.

Hope it helps.

Share this post


Link to post
Share on other sites
one potential way to allow you to use different color keys for different images is as follows: leave yourself a little border area of known proportion to the image at the beginning or somewhere, and set it to the color you want to use as your key. Sample that color, and then compare against it for purposes of keying.

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!