I need to load a PNG with a transparency and then use al_draw_bitmap_region() to draw that into another bitmap, but it seems to be putting black for the transparent color.
I think it's because my bitmap is being "cleared" to black before the PNG is loaded. Is there a way to al_clear_to_color() where the color is transparent?
(Allegro 5 BTW)
Chris, that thread is way outdated. It's so old the function signature for al_set_blender is different.
PNGs are loaded exactly as they are stored. There is no conversion of anything to anything.
If your bitmap is drawing black, it's probably because your blender is wrong.
The default blender is (ALLEGRO_ADD , ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA) for premultiplied alpha blending.
Try saving the png with allegro. It should come out exactly the same as the png you loaded.
I thought he meant he was drawing one image to another, but it wasn't moving the ALPHA, it was just USING the alpha.
Hence the blender changes.
Here is some example code (I attached the example picture too)
This is just the mockup but here is the idea.
I have a buffer that I used for cut/paste operations. I will copy a bitmap with transparencies to this buffer and then copy from this buffer to somewhere else later. However, where on the buffer things are cut/paste are random so I need to clear the buffer back to transparent so it can accept another paste.
The logic goes like this
clear buffer to transparent -> paste graphic to hold in the buffer -> copy from buffer to target bitmap.
If I paste a graphic on the buffer when the buffer is black, I lose the transparency.
So I would like to clear the buffer to transparent before I do a cut and paste.
===EDIT===
Got it!
al_set_target_bitmap(buffer); al_clear_to_color(al_map_rgb(0, 0, 0)); al_convert_mask_to_alpha(buffer, al_map_rgb(0, 0, 0));
Took me a bit, but it was simpler then I thought.
In old Allegro 4, using the DX backend, clear to color ignored the alpha channel. I don't think Allegro 5 does that though.
You should be able to clear to an alpha color, using al_map_rgba. If that doesn't work, then you can draw a filled rectangle over the entire bitmap using an overwrite blender.
The al_map_rbga() clear worked. Thanks!