Sign in to follow this  
Chrono1081

Is there an advantage in color keying a sprite vs embedded transparency?

Recommended Posts

Hi guys. I was curious on whether there are advantages/disadvantages to having sprites with embedded transparency vs color keying. (I actually think color keying would be more convenient since a lot of downloadable sprite libraries use this) but I thought I would ask. This would be using C++ and SDL.

Share this post


Link to post
Share on other sites
Color keying means less file size since the Alpha channel dosen't have to be saved in an image. However, in the end it was more efficient for me to use PNG files with transparency over color-keying SDL Surfaces. But then again, thats my own opinion here. :)

Share this post


Link to post
Share on other sites
If using SDL to do all of your rendering and not OpenGL then you may see a huge performance hit using alpha blending over color keys. How much of a difference it makes is really dependent on how much alpha blending is being used.

The difference between using alpha blending and color keys when using SDL to render (i.e. SDL_BlitSurface) is that SDL will ignore pixels with a color key value however it will still do some processing on alpha blended pixels (although I believe there are optimizations for values of 0 and 128).

Think of it this way - color keying is basically saying any pixel with this color will always be transparent. SDL can "skip" even sending these pixels to the back buffer.

Alpha blending is more complicated because it takes the source color and blends it with the destination color based on the alpha value. This is done in software on SDL so your game will wait for SDL to compute this value instead of just skipping it.

When using OpenGL or DirectX the information just gets sent to your graphics card and it figures out the alpha blending on it's own MUCH faster than SDL does by itself. In fact many people will recommend using a 3d API for doing 2d just because you are basically able to do alpha blending on the graphics card "for free" meaning you don't take the performance hit you do when using SDL alone. The same is often said about rotation and scaling as well.

An easy way to remember this - the most efficient pixel to draw on the screen is the one you never draw.

Share this post


Link to post
Share on other sites
Thank you guys for all the responses :)

I will have to look in to using Open GL with SDL. I have a book on Open GL so I will have to peek and see if it gives me the info I am looking for.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this