Handmade Hero»Forums»Code
Bitmap Unused High Byte
When we set the Bitmap as 32bit and told it to use RGB, we are assigning values to only 3 of the 4 bytes in one pixel (0xXRGB, where X is unused byte). Can I use this byte for other purposes for does it have to remain 0?
Mustafa Al-Attar
19 posts
Working in a software company since 2008 and still. Has been working on an rpg in C++ with OpenGL since 2015 and still.
Bitmap Unused High Byte
Hi there...

Usually this byte is used to represent Alpha, which is the transparency of the color. What happens usually is that the texture get blended with the one underneath.

Example:

If you have your hero/sprite drawn first, then you could draw a "water tile" above your sprite with alpha set to ( 128 ). You will end up with the hero/sprite blended with the water tile - water tile being half transparent - . As far as I know, this technique is called alpha blending.

Notice however that the code in its current state does not perform blending because the pixels are being copied manually - you might want to check with others to make sure I am not mistaken -. I guess Casey is going to implement that later if there isn't a windows API that does this kind of thing.

Yours sincerely

mkaatr
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Bitmap Unused High Byte
In the offscreen buffer, yes, you can use the fourth byte for whatever you want. Since we are not asking Windows to do alpha compositing, I'm pretty sure it will never look at what's in there. StretchDIBits will simply discard it.

In our art resources, you'll see us use that fourth byte for alpha.

- Casey