alpha on back buffer
Matthew Leverton

Why do I get different behavior when I run this on the back buffer vs a video bitmap?

al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);

al_clear_to_color(al_map_rgba_f(0,0,0,1));
c = al_get_pixel(al_get_target_bitmap(), 0, 0);    
printf("%f %f %f %f\n", c.r, c.g, c.b, c.a);

al_draw_pixel(0.5,0.5, al_map_rgba_f(1,0,0,0));
c = al_get_pixel(al_get_target_bitmap(), 0, 0);    
printf("%f %f %f %f\n", c.r, c.g, c.b, c.a);

Output using display's back buffer:

0,0,0,1 
1,0,0,1

But I'd expect the second line to be 1,0,0,0, and the pixel not to be drawn.

Elias

I assume your back buffer has no alpha channel - you can check it with al_get_bitmap_format(al_get_target_bitmap()).

X-G

It still shouldn't draw the pixel, should it..?

Elias

ADD/ONE/ZERO means the r/g/b/a value simply is copied as is. So his 1/0/0/0 pixel is copied to the target. The alpha channel only matters when you use a blend mode of ALPHA or INVERSE_ALPHA somewhere.

Arthur Kalliokoski

You mean the order of his 1's and 0's is AGBR and the incorrect alpha value should be disregarded?

Elias

No, he draws a pixel with r=1,g=0,b=0,a=0. With a blend mode of ADD/ALPHA/INVERSE this would mean that r/g/b/a is multiplied with a first so everything is multiplied with 0 so it all gets 0. Nothing at all is drawn. With the blend mode he uses (ADD/ONE/ZERO) the r/g/b/a are simply copied (the destination is multiplied with 0, the source is multiplied with 1 therefore left as is). The alpha value (a=0) is not used at all.

The only unexpected thing is that when he reads the pixel back the alpha magically turned 1. This is a bug if the bitmap does have an alpha channel, otherwise is expected (a bitmap without alpha always behaves like a bitmap with an alpha channel of all 1).

X-G

Yeah, I didn't see the al_set_blender call.

Matthew Leverton
Elias said:

I assume your back buffer has no alpha channel - you can check it with al_get_bitmap_format(al_get_target_bitmap()).

Pixel format is reported to be ALLEGRO_PIXEL_FORMAT_ABGR_8888 on both the backbuffer and the video bitmap.

Elias

Sounds like a bug then - I guess the backbuffer never has actual alpha without doing something special. Is this with OpenGL?

Matthew Leverton
Elias said:

Is this with OpenGL?

Yes.

How is one supposed to set the back buffer format with Allegro?

Neil Walker

Trying not to sound stupid, could it be something to do with the position and not the colour? as in one buffer is interpreting 0.5 at the wrong location?

J-Gamer

0.5,0.5 is the middle of the pixel in the top left corner, so it will always flag that one.

Elias

How is one supposed to set the back buffer format with Allegro?

You're not supposed to use anything but the default :P In all other cases, you can use al_set_new_display_option.

Neil Walker

I like the integration of the forum with the manual. Very cool.

Thread #606098. Printed from Allegro.cc