Hey there…

I’ve searched on this subject here and didnt find anything really usefull, so here’s a new post on it

I currently use a second jpg texture to load an alpha channel and want to use another approach.

Loading TGA textures will just increase my texture size, so thats not what i want eigther.

I was thinking about checking each rgb value of my jpg and assigning an alpha value of 0 to it when it is pink for example, while loading the texture in my code.

Could anyone help me on my way?

I think i should:

put alpha testing on;
for loop thru;
create alpha channel (how??);
store new texture data;

thx in advance


I just wanted to say that using TGA’s is not so bad at all.
You know, when you have loaded the imagefile into memory it takes the same space in every format.

[Or were you hinting at that the alpha-channel is to big? Then of course you are right. TGA are nice though ]

Ummm sorry that I could not really help you.

Now I noticed that you want to create an alpha channel during runtime. Hey, I would really go for a TGA. Because it’s easy.
If you are worried about the space your textures take on your harddrive you could use something like zlib to store it.

Hope that helps

[This message has been edited by B_old (edited 11-11-2002).]

ofcourse, in raw format its almost the same, but im talking about discspace/dowload space

thx anyway

Like I said. Compress it.

You even end up with better quality

[This message has been edited by B_old (edited 11-11-2002).]

ok thx for your reply, but i said in my post i didnt want to use TGA, so please dont try to work around my problem.

I want to mask a certain color period .

I know its certainly possible.

I might want to try TGA anyway, but i still want to know how to create an alpha channel from withing OpenGL


Very well then. I just wanted to help you.
I guess you did not know, but I use TGA myself.
Well, OK. I will shut my mouth know and don’t trouble you any further.
Sorry that I could not help you with your actual problem.

Basic pseudo-code for what you want is fairly easy.

unsigned char* pNewData;

pImg = LoadJPEG(“image.jpg”);

pNewData = new unsigned char[pImg->wpImg->h4);

for (int y=0;yh;y++)
for (int x=0;xw;x++)
int iIndex = y*pImg->w+x;

   pNewData[iIndex*4] = pImg->data[iIndex*3];
   pNewData[iIndex*4 + 1] = pImg->data[iIndex*3 + 1];
   pNewData[iIndex*4 + 2] = pImg->data[iIndex*3 + 2];

   if (pImg->data[iIndex*3] == 0 &&
       pImg->data[iIndex+3+1] == 0 &&
       pImg->data[iIndex+3+2] == 0)
        desiredAlpha = 128;
        desiredAlpha = 255;

   pNewData[iIndex*4 + 3] = desiredAlpha;  


The above code will basically find any pixel that is black, and give it an alpha of 128, and give every other pixel a value of 255.

You could modify the above to use any specific color you wanted, or you could modify it to use a range of colors, or pretty much anything you wanted.

Edit: My pseudo code was assigning float values to unsigned chars. Not good.

[This message has been edited by Deiussum (edited 11-11-2002).]

ok thx mate you rule.