• Advertisement

Archived

This topic is now archived and is closed to further replies.

Anyone here can code translucency?

This topic is 6060 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

Well, I need some help. I just want to make my images translucent, meaning that it can be seen through. Using a 16-bit image, how do I go about doing it? A reference towards the book "Tricks of the Game Programming Guru 1999 Edition"''s t3dlib1 could be very helpful. Thanx! - Haz -

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster

For every pixel of the source image (foreground image), extract the red, green, and blue values. Average each red, green, and blue value with the red, green, and blue value of every overlapping pixel of the destination (background image). Combine the red, green, and blue values into a 16-bit color word. Write this word into your destination buffer.

If you code this straightforward and brute force, I promise it will be slow. There are things you might do to make it faster, such as look up tables:


// build a translucency lookup table
unsigned char transtable[100][32][32];
for(int t=0;t<100;t++)
for(int a=0;a<32;a++)
for(int b=0;b<32;b++)
transtable[t]
You can try calculating the averages on the fly using this:


red = ((a.red*t)+(b.red*(64-t)))>>6;
green = ((a.green*t)+(b.green*(64-t)))>>6;
blue = ((a.blue*t)+(b.blue*(64-t)))>>6;


Where t is in the range 0-64; 32 would be 50% translucent. But if you are just looking for 50% translucent, try this:


red = (a.red + b.red)>>1;
green = (a.green+ b.green)>>1;
blue = (a.blue + b.blue)>>1;


There are probably more efficient ways to do all this, but this is the general idea.
' Target=_Blank>Link

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

Don''t know what the hell happened there.

The code should look like:



// build a translucency lookup table
unsigned char transtable[100][32][32];
for(int t=0;t<100;t++)
for(int a=0;a<32;a++)
for(int b=0;b<32;b++)
transtable[t]Link

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

Don''t know what the hell happened there.

The code should look like:

  

// build a translucency lookup table

unsigned char transtable[100][32][32];
for(int t=0;t<100;t++)
for(int a=0;a<32;a++)
for(int b=0;b<32;b++)
transtable[t][a][b] = ((a*t)+(b*(100-t)))/100;








Share this post


Link to post
Share on other sites

  • Advertisement