PDA

View Full Version : Masking



xill
11-11-2002, 06:19 AM
Hey there..

I've searched on this subject here and didnt find anything really usefull, so here's a new post on it http://www.opengl.org/discussion_boards/ubb/smile.gif

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 texture.data;
create alpha channel (how??);
store new texture data;

thx in advance

cya

B_old
11-11-2002, 07:50 AM
Hello.
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 http://www.opengl.org/discussion_boards/ubb/smile.gif]

Ummm sorry that I could not really help you.

EDIT:
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).]

xill
11-11-2002, 07:53 AM
ofcourse, in raw format its almost the same, but im talking about discspace/dowload space

thx anyway

B_old
11-11-2002, 07:55 AM
Like I said. Compress it.

EDIT:
You even end up with better quality http://www.opengl.org/discussion_boards/ubb/smile.gif

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

xill
11-11-2002, 08:11 AM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif.

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

-xill

B_old
11-11-2002, 08:17 AM
Very well then. I just wanted to help you.
I guess you did not know, but I use TGA myself.
http://www.opengl.org/discussion_boards/ubb/smile.gif 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.

Deiussum
11-11-2002, 10:44 AM
Basic pseudo-code for what you want is fairly easy.




unsigned char* pNewData;

pImg = LoadJPEG("image.jpg");

pNewData = new unsigned char[pImg->w*pImg->h*4);

for (int y=0;y<pImg->h;y++)
{
for (int x=0;x<pImg->w;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 &amp;&amp;
pImg->data[iIndex+3+1] == 0 &amp;&amp;
pImg->data[iIndex+3+2] == 0)
{
desiredAlpha = 128;
}
else
{
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. http://www.opengl.org/discussion_boards/ubb/smile.gif

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

xill
11-12-2002, 12:21 PM
ok thx mate you rule.