Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » alpha on back buffer

This thread is locked; no one can reply to it. rss feed Print
alpha on back buffer
Matthew Leverton
Supreme Loser
January 1999
avatar

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
Member #358
May 2000

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

--
"Either help out or stop whining" - Evert

X-G
Member #856
December 2000
avatar

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

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Elias
Member #358
May 2000

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.

--
"Either help out or stop whining" - Evert

Arthur Kalliokoski
Second in Command
February 2005
avatar

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

They all watch too much MSNBC... they get ideas.

Elias
Member #358
May 2000

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).

--
"Either help out or stop whining" - Evert

X-G
Member #856
December 2000
avatar

Yeah, I didn't see the al_set_blender call.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Matthew Leverton
Supreme Loser
January 1999
avatar

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
Member #358
May 2000

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

--
"Either help out or stop whining" - Evert

Matthew Leverton
Supreme Loser
January 1999
avatar

Elias said:

Is this with OpenGL?

Yes.

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

Neil Walker
Member #210
April 2000
avatar

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?

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

J-Gamer
Member #12,491
January 2011
avatar

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

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Elias
Member #358
May 2000

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.

--
"Either help out or stop whining" - Evert

Neil Walker
Member #210
April 2000
avatar

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

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Go to: