• Advertisement
Sign in to follow this  

Ignoring a color when drawing and image

This topic is 4453 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've been using targa to draw images to the screen using openGL. However, I'd like to ignore the color white. I don't want to draw white pixels to the screen, otherwise I get an ugly white box surrounding my sprites. How can I do this?

Share this post


Link to post
Share on other sites
Advertisement
That's called color keying.

I don't know why you would want to do that since targa supports transparency but:
to make one color transparent you just have to take your image before it is sent to the drawing API (OpenGL), loop through all it's pixels and if it's color is white then you set this pixel's alpha value (transparency) to zero (fully transparent).

How exactely you should do that depends on how you are loading, storing and passing this image to the rendering API, so you could post some code to help us help you :)

Googling for 'color keying' should help a bit too.

Edit:

Here's a bit of code:


void SetAlphaFromColor(unsigned char *pImage, int Size)
{
int i;
for(i = 0; i < Size; i += 4)
{
if(pImage == 255 && pImage[i + 1] == 255 && pImage[i + 2] == 255)
pImage[i + 3] = 0;
}

return;
}



That function should accept a image as an array of 'unsigned char' in the RGBA format (red-green-blue-alpha -> 4 chars per pixel) and the size of the array and it should make the white color transparent.

Share this post


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

  • Advertisement