![]() |
|
Help with blender and alpha masking |
Michael Weiss
Member #223
April 2000
|
I am new to the whole blender thing and have spent many hours trying I am trying to draw a bitmap onto the backbuffer and blend it with the This code from the examples works great: al_set_blend_color(al_map_rgba_f(0.5, 0.5, 0.5, 0.5)); But my source bitmap has an alpha channel, and I can't figure out how I have tried al_set_separate_blender with many different combinations I have read the docuemntation many times, and looked at other explanations Here is a simple test program: 1// this draws a background of colored squares
2 ALLEGRO_COLOR c[5];
3 c[0] = al_map_rgb(255, 0, 0);
4 c[1] = al_map_rgb(0, 255, 0);
5 c[2] = al_map_rgb(0, 0, 255);
6 c[3] = al_map_rgb(255, 255, 255);
7 c[4] = al_map_rgb(0, 0, 0);
8
9 al_set_target_backbuffer(display);
10 al_flip_display();
11 al_clear_to_color(al_map_rgb(0,0,0));
12
13 int ci = 0;
14 for (int y=0; y<10; y++)
15 for (int x=0; x<10; x++)
16 {
17 al_draw_filled_rectangle(x*20, y*20, x*20+20, y*20+20, c[ci]);
18 if (++ci>2) ci = 0;
19 }
20
21
22
23// this is the bitmap I am drawing
24 sprintf(msg, "Test") ;
25 int sw = strlen(msg) * 8;
26 ALLEGRO_BITMAP *temp = al_create_bitmap(sw, 8);
27 al_set_target_bitmap(temp);
28 al_clear_to_color(al_map_rgb(0,0,0));
29 al_draw_text(font, ci[3], sw/2, 0, ALLEGRO_ALIGN_CENTRE, msg);
30 al_convert_mask_to_alpha(temp, al_map_rgb(0, 0, 0));
31
32
33// here is where I have tried just about every blender combination I can think of
34
35 al_set_blend_color(al_map_rgba_f(0.5, 0.5, 0.5, 0.5));
36 al_set_blender(ALLEGRO_ADD, ALLEGRO_CONST_COLOR, ALLEGRO_CONST_COLOR);
37
38
39
40// this is where i actually draw it
41 al_set_target_backbuffer(display);
42 al_draw_scaled_rotated_bitmap(temp, sw/2, 4, 88, 48, 4, 4, 0, 0);
43 al_flip_display();
44 al_destroy_bitmap(temp);
When I don't specify any blender I get a nice masked text over background. When I try this: I get a nice blended source and dest, just like what I wanted, I tried: I tried: al_set_blend_color(al_map_rgb_f(0.5, 0.5, 0.5)); 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 Thanks
|
Dizzy Egg
Member #10,824
March 2009
![]() |
Try: al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); OR al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
---------------------------------------------------- |
Michael Weiss
Member #223
April 2000
|
Hi Dizzy Egg, al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE); I also tried: al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); al_set_blend_color(al_map_rgb_f(0.5, 0.5, 0.5)); al_set_blend_color(al_map_rgb_f(0.5, 0.5, 0.5)); al_set_blend_color(al_map_rgb_f(0.5, 0.5, 0.5)); I want something that has blending and alpha mask... Does the pixel format have anything to do with it? temp pixel format: Thanks
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Try al_draw_tinted_bitmap with al_map_rgba_f(0.5,0.5,0.5,0.5). My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Neil Roy
Member #2,229
April 2002
![]() |
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. --- |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
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. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Neil Roy
Member #2,229
April 2002
![]() |
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) --- |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
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. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Michael Weiss
Member #223
April 2000
|
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. Thanks again.
|
|