Ignoring a color when drawing and image

Started by
0 comments, last by RaptorZero 18 years, 5 months ago
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?
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 == <span class="cpp-number">255</span> &amp;&amp; pImage == <span class="cpp-number">255</span>)<br>			pImage = <span class="cpp-number">0</span>;<br>	}<br><br>	<span class="cpp-keyword">return</span>;<br>}<br><br></pre></div><!–ENDSCRIPT–><br><br>That function should accept a image as an array of 'unsigned char' in the RGBA format (red-green-blue-alpha -&gt; 4 chars per pixel) and the size of the array and it should make the white color transparent.
error C2065: 'signature' : undeclared identifier

This topic is closed to new replies.

Advertisement