Some functions I've been using require me to input colors in 0xAABBGGRR format [UINT32]
It would be a much more user-friendly interface if this could be accomplished with RGBA float values, ranged from 0 to 1 as they normally are.
Is there a simple way to accomplish this?
To make my question more clear,
UINT32 ColorValue(float r, float g, float b, float a) {
// ???
}
Example: ColorValue(1,0,0,1) == 0xFF0000FF
Since, I presume, you are interested in learning, I'm not going to post an answer that you can just paste into your code, instead I'll explain the components you need:
<<
operator, so x << y
shuffles the value of x
to the left by y
bits. |
operator. In this case, 0xFF | 0xFF0000
would become 0xFF00FF
.The rest is just taking the lego pieces I've described above and putting them together in the right places.