Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualeppo

Posted 09 March 2013 - 01:48 PM

You have an inconsistency in your code here:

 

(int)ptrOutput[4 * x * 1] should be: (int)ptrOutput[4 * x + 1] (for both the green and the blue channels.)

 

...but the real problem is that you can't use bitwise masking to perform alpha blending (only 1-bit alpha testing).

 

Consider the color value 170 (10101010) and an alpha value of 85 (1010101). AND-ing them together would result in the value 0 (00000000), while the expected value (of a multiplication of the two) would be 170 * 85 / 255 = 56. An OR operation would result in the value 255 (11111111).

 

 

More correct would be: newcolor = ((basecolor * (255 - alpha)) + (covercolor * alpha)) / 255.


#1eppo

Posted 09 March 2013 - 01:46 PM

You have an inconsistency in your code here:

 

(int)ptrOutput[4 * x * 1] should be: (int)ptrOutput[4 * x + 1] (for both the green and the blue channels)

 

...but the real problem is that you can't use bitwise masking to perform alpha blending (only for 1-bit alpha testing).

 

Consider the color value 170 (10101010) and an alpha value of 85 (1010101). AND-ing them together would result in the value 0 (00000000), while the expected value is 170 * 85 / 255 = 56. An OR operation would result in the value 255 (11111111).

 

More correct would be: newcolor = ((basecolor * (255 - alpha)) + (covercolor * alpha)) / 255.


PARTNERS