![]() |
|
Draw rectangle with alpha |
mentalDisorder
Member #13,376
August 2011
|
Hi ALLEGRO_COLOR color = al_map_rgba(100 , 100, 200, 255); al_clear_to_color(al_map_rgb(0,0,0)); Rectangle is drawn but alpha channel is ignored. |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
Did you set_color_depth(32) before setting video mode? They all watch too much MSNBC... they get ideas. |
mentalDisorder
Member #13,376
August 2011
|
No, because I use allegro5 and there isn't such a function. |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
I really need to pay more attention Maybe this will help. http://www.allegro.cc/forums/thread/606420 This manual has links to allegro.cc questions concerning the function in question They all watch too much MSNBC... they get ideas. |
mentalDisorder
Member #13,376
August 2011
|
Have no idea what to do with al_set_new_display_option and al_set_blender functions. |
Elias
Member #358
May 2000
|
You need to multiply the color components with the alpha. -- |
mentalDisorder
Member #13,376
August 2011
|
yes I know how RGBA system works but I don't know how to tell allegro5 to use alpha channel ! |
Elias
Member #358
May 2000
|
It always uses alpha. My point was that (255, 255, 255, 128) will not be transparent as you might have expected. Edit: I.e. (128, 128, 128, 128) will be 50% transparent white, not gray as I said above. If you use floating point, then basically if you have a color (r, g, b) and want to add alpha, you need to use: (r * a, g * a, b * a, a). So if you want 50% transparent red, you would use (1, 0, 0, 1) * 0.5 = (0.5, 0, 0, 0.5). -- |
Chris Katko
Member #1,881
January 2002
![]() |
Elias said: I.e. (128, 128, 128, 128) will be 50% transparent white, not gray as I said above. If you use floating point, then basically if you have a color (r, g, b) and want to add alpha, you need to use: (r * a, g * a, b * a, a). So if you want 50% transparent red, you would use (1, 0, 0, 1) * 0.5 = (0.5, 0, 0, 0.5). I don't think I've used those routines before then. Could you explain why you have to multiply the color values by the alpha to be transparent? -----sig: |
Elias
Member #358
May 2000
|
Well, if you look here http://www.liballeg.org/a5docs/refman/graphics.html#al_set_blender r = d.r * df.r + s.r * sf.r g = d.g * df.g + s.g * sf.g b = d.b * df.b + s.b * sf.b a = d.a * df.a + s.a * sf.a Then the default blend mode al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA) means you get: r = d.r * (1-s.a) + s.r * 1 g = d.g * (1-s.a) + s.g * 1 b = d.b * (1-s.a) + s.b * 1 a = d.a * (1-s.a) + s.a * 1 So if the source color is (1,1,1,0.5) and the dest color is (0,0,0) you get: r = 0 * (1-0.5) + 1 * 1 = 1 g = 0 * (1-0.5) + 1 * 1 = 1 b = 0 * (1-0.5) + 1 * 1 = 1 So you are drawing fully opaque white. But what you want is to use (0.5,0.5,0.5,0.5) as source color: r = 0 * (1-0.5) + 0.5 * 1 = 0.5 g = 0 * (1-0.5) + 0.5 * 1 = 0.5 b = 0 * (1-0.5) + 0.5 * 1 = 0.5 This time we were drawing a 50% transparent white pixel onto the black destination pixel correctly. If you change the blend type to al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA) then the blending itself will do that multiplication for you, but see ex_premul_alpha for why that is a very bad idea with OpenGL/DirectX. -- |
|