I am new to the whole blender thing and have spent many hours trying
to figure out what I though would be a simple task.
I am trying to draw a bitmap onto the backbuffer and blend it with the
backbuffer.
This code from the examples works great:
al_set_blend_color(al_map_rgba_f(0.5, 0.5, 0.5, 0.5));
al_set_blender(ALLEGRO_ADD, ALLEGRO_CONST_COLOR, ALLEGRO_CONST_COLOR);
But my source bitmap has an alpha channel, and I can't figure out how
to get that respected...no matter how many different combination I try
I always get the zero pixels blended also.
I have tried al_set_separate_blender with many different combinations
and gotten nowhere.
I have read the docuemntation many times, and looked at other explanations
of blending of the web. But I can't seem to make it work.
Here is a simple test program:
When I don't specify any blender I get a nice masked text over background.
When I try this:
al_set_blend_color(al_map_rgba_f(0.5, 0.5, 0.5, 0.5));
al_set_blender(ALLEGRO_ADD, ALLEGRO_CONST_COLOR, ALLEGRO_CONST_COLOR);
I get a nice blended source and dest, just like what I wanted,
except the alpha is not respected and I get a rectangle around the text.
I tried:
al_set_blend_color(al_map_rgba_f(0.5, 0.5, 0.5, 0));
al_set_blend_color(al_map_rgba_f(0.5, 0.5, 0.5, 1));
al_set_blend_color(al_map_rgb_f(0.5, 0.5, 0.5));
but they all made no difference.
I tried:
al_set_blend_color(al_map_rgb_f(0.5, 0.5, 0.5));
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_CONST_COLOR, ALLEGRO_CONST_COLOR, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
al_set_blend_color(al_map_rgb_f(0.5, 0.5, 0.5));
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_CONST_COLOR, ALLEGRO_CONST_COLOR, ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_ZERO);
plus many more combinations, but I can never get the alpha mask to work...
Can anyone with more experience with blenders help me?
Do I somehow have to do this with 2 steps?
My overall goal is simply to have a partially transparent bitmap superimposed over
another bitmap (the backbuffer), (kind like a water mark), but I want it masked so the
zero pixels are not blended with the background.
Thanks
Try:
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); OR al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
Hi Dizzy Egg,
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
- no blending and no alpha mask
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
- no blending, but alpha mask works (same as no blender at all)
I also tried:
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
- no blending and no alpha mask
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
- no blending, but alpha mask works
al_set_blend_color(al_map_rgb_f(0.5, 0.5, 0.5));
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_CONST_COLOR, ALLEGRO_CONST_COLOR, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
- blending, but no alpha mask
al_set_blend_color(al_map_rgb_f(0.5, 0.5, 0.5));
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_CONST_COLOR, ALLEGRO_CONST_COLOR, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
- blending, but no alpha mask
al_set_blend_color(al_map_rgb_f(0.5, 0.5, 0.5));
al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_CONST_COLOR, ALLEGRO_CONST_COLOR, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
- blending, but no alpha mask
I want something that has blending and alpha mask...
Does the pixel format have anything to do with it?
temp pixel format:
ALLEGRO_PIXEL_FORMAT_ARGB_8888
backbuffer pixel format:
ALLEGRO_PIXEL_FORMAT_RGB_565
Thanks
Try al_draw_tinted_bitmap with al_map_rgba_f(0.5,0.5,0.5,0.5).
You need to use al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); BEFORE you create your display, not afterwards.
Note: the options are just ones I use in my Deluxe Pacman 2 game, yours may differ.
Poppycock. You can change the blender anytime you want, except when drawing is held.
What you just quoted is the pre-multiplied alpha blender, which is the default.
I just tested that, you're right, no longer needed. But I needed to add it at one point so I will assume something changed. Good to know anyhow, even with Edgar's usual charming, kind replies.
My only guess would be that it has to do with al_convert_mask_to_alpha(temp, al_map_rgb(0, 0, 0));. It's not a function I have ever used but what mask is it converting? And what alpha is it making it? Is it expecting the bitmap to already have a mask? (awaits another rude response from Edgar)
If I'm being fresh it's because I dislike bad advice. :/
al_convert_mask_to_alpha takes a mask color, compares it to every pixel, and writes zero alpha if it matches.
Thanks Edgar!
your suggestion:
Try al_draw_tinted_bitmap with al_map_rgba_f(0.5,0.5,0.5,0.5).
Did exactly what I was looking for.
I didn't even look at the tinted drawing functions.
If I would have I would have found your exact suggestion as an example.
Thanks again.