Hey everyone. My artist wants to do a kind of gradient in his art for our simple 2D game. He wants to do something like Green fading to Transparent. I could hard code this in, but he wants it to be part of the actual image file so he can visualize it when drawing the art.
This seems like a reasonable request, but it turns out to be kind of difficult. I'm using the SDL API, which allows me to use the SDL_SetColorKey() function which will allow me to set all pixels of a certain RGB value to transparent. The trouble is that any pixel which is slightly off from that (like a pixel that is slightly greener than purely my transparent color) will not be changed to transparent, and certainly won't leave the green color behind.
I hope you guys can understand the issue here... Does anybody have some resources they could direct me to to solve this dilemma or does anybody have an idea themselves?
Not all image formats support alpha channels. For example, the JPG format doesn't support any type of transparency at all. GIF supports transparency, but not alpha channels. IE the whole image has to have the same level of transparency. PNG is a format that fully supports alpha channels, which allows you to specify the transparency on a per pixel basis.
The SDL_SetColorKey() function is for binary transparency (off or on).
You want to mess with the alpha channel. First, make sure the image has one. Then you need to mess with the individual pixel data. There is no single SDL function call to do that. It requires some programming.
You could programmatically create the image in SDL.
Or you could just use the GIMP or something to create it.
Then composite the two images together in the SDL game (put his art over top of the green gradient)...