#5
In this expression:

Code:

(color.components[COMPONENT_RED] / 0xff)

The type of color.components[COMPONENT_RED] is char (one of the integer types, as distinct from floating-point or pointer types), and the type of 0xff is an integer compile-time constant. So the expression is evaluated using integer arithmetic.

Unfortunately for you, you need the expression to be evaluated in floating-point arithmetic, otherwise all values of char that are less than 0xff will produce a net result of 0. To understand why, think about what the runtime result would be for two integer constants:

It should be clear that all values of the numerator below 0xff will result in 0. If the color you want is black, fine. But think about what effect that has on alpha.

The fix is to change your compile-time expression term from 0xff to 255.0. With a decimal point and a 0 fractional part, it's now a floating-point expression, and the compile-time operands are all promoted to floating-point (same as runtime).