Game Development Reference
In-Depth Information
destinationtype.WeareusingARGBasoutformat,thismeansthatthealphachannelisthe
first value we need to place at the leftmost position of our 32-bit value. We will look at the
bit manipulation operations we need to perform in order to combine all the color channels
into a single color, this is a very brief introduction to a very small part of bit manipulation,
if you are already comfortable manipulating bits, feel free to skip ahead.
Ifwedisplaythealphachannel(FF)asa32bitvalue,wewouldseeitprecededbysixzeros.
000000FF
If we go further, in binary, this is
0000 0000 0000 0000 0000 0000 1111 1111
We count the number of 0's that would place our alpha value at the leftmost position, start-
ing from the leftmost 1, this means we need to shift our value 24 positions to the left.
1111 1111 0000 0000 0000 0000 0000 0000
Which back in hexadecimal notation puts the alpha at the leftmost position of the 32-bit
value.
(000000FF << 24) = FF000000
Nextupistheredchannel,similarlywefindthatweneedtoshifttheredcolorintoposition,
doing the same procedure we find we need to shift by 16,
(000000FF << 16) = 00FF0000
Then we shift the green channel by 8 bits.
(000000FF << 8) = 0000FF00
Andfinally,the blue channel is already at the rightmost position sothere is noneed toshift
it. The final step in the process is to combine the channels into a single 32-bit value at their
respective positions. With the bitwise OR operator we compare two bits, if either bit is 1,
the resulting bit will be 1, for example:
10110010 |
00100101 =
--------
10110111
Search WWH ::




Custom Search