Jump to content
  • Advertisement
Sign in to follow this  
Hachaso

Untitled

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

Hi! I need some help with alpha blending. What I have done, is to write 2 different functions that are supposed to return the same value. The problem is that something is different and I can't seem to figure out what. I have done it by hand to see that the calculation is correct and still nothing. Please tell me if I'm on the right track. Is that the way to do alpha blending? And also what is the difference between the two functions? Here's the code: Alpha is mapped to a value between 0 - 32. If I understand correct, alpha originally is a float containing a value between 0.0 - 1.0. So now I have mapped alpha to an unsigned char value between 0 - 32. unsigned short rgb565Blender1(unsigned short ColorA, unsigned short ColorB, unsigned char Alpha) { unsigned short res = 0; unsigned short ColorAred = 0; unsigned short ColorAgreen = 0; unsigned short ColorAblue = 0; unsigned short ColorBred = 0; unsigned short ColorBgreen = 0; unsigned short ColorBblue = 0; unsigned short resR = 0; unsigned short resG = 0; unsigned short resB = 0; ColorAred = ColorA & (0x1f << 11); ColorBred = ColorB & (0x1f << 11); ColorAgreen = ColorA & (0x3f << 5); ColorBgreen = ColorB & (0x3f << 5); ColorAblue = ColorA & 0x1f; ColorBblue = ColorB & 0x1f; resR = ((Alpha*(ColorAred - ColorBred)) >> 5) + ColorBred; resG = ((Alpha*(ColorAgreen - ColorBgreen)) >> 5) + ColorBgreen; resB = ((Alpha*(ColorAblue - ColorBblue)) >> 5) + ColorBblue; res = resR | resG | resB; return res; } Next function here with some minor differences. unsigned short rgb565Blender2(unsigned short ColorA , unsigned short ColorB , unsigned char Alpha) { unsigned short res = 0; unsigned short ColorAred = 0; unsigned short ColorAgreen = 0; unsigned short ColorAblue = 0; unsigned short ColorBred = 0; unsigned short ColorBgreen = 0; unsigned short ColorBblue = 0; unsigned short resR = 0; unsigned short resG = 0; unsigned short resB = 0; ColorAred = (ColorA >> 11) & 0x1f; ColorBred = (ColorB >> 11) & 0x1f; ColorAgreen = (ColorA >> 5) & 0x3f; ColorBgreen = (ColorB >> 5) & 0x3f; ColorAblue = ColorA & 0x1f; ColorBblue = ColorB & 0x1f; resR = (Alpha*(ColorAred - ColorBred) >> 5) + ColorBred; resG = (Alpha*(ColorAgreen - ColorBgreen) >> 5) + ColorBgreen; resB = (Alpha*(ColorAblue - ColorBblue) >> 5) + ColorBblue; resG = resG << 5; resR = resR << 11; res = resB | resG | resR; return res; } Thanks for the help!

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!