|
Transparency examples |
BigGiantBrain
Member #8,769
June 2007
|
I'd like to add transparency to my A5 application's menus, and am seeking a programming example or tutorial. Thanks. |
Trent Gamblin
Member #261
April 2000
|
If you want to draw a transparent rectangle, set the color like this: float r = red; float g = green; float b = blue; float a = alpha; // 0-1, 0 = fully translucent, 1 = fully opaque ALLEGRO_COLOR color = al_map_rgba_f(r*a, g*a, b*a, a); // now draw primitives with 'color' For images it's almost the same thing, except normally you don't want to tint the image so you use: ALLEGRO_COLOR color = al_map_rgba_f(a, a, a, a); al_draw_tinted_bitmap(bitmap, color, x, y, flags);
|
BigGiantBrain
Member #8,769
June 2007
|
I'll play with that... Thanks for the response. |
Trent Gamblin
Member #261
April 2000
|
r, g, b are also 0-1 BTW.
|
BigGiantBrain
Member #8,769
June 2007
|
I am trying ad a tint to the entire clipped airspeed window below. The test below generates a non-specific debug error: where am I going wrong? float r = .5; |
Trent Gamblin
Member #261
April 2000
|
"non-specific"? What is the error.
|
BigGiantBrain
Member #8,769
June 2007
|
I get a MSVC Debug Library pop up: Debug Error! R6010 ABORT RETRY IGNORE |
Trent Gamblin
Member #261
April 2000
|
Sounds to me like the bitmap is NULL. Try printing its value before drawing it.
|
BigGiantBrain
Member #8,769
June 2007
|
I agree, however commenting out the 6 lines of transparancy test code eliminates the error. The error is generated on the line that calles al_draw_tinted_bitmap...does the transparency funtionality require a library #include? Please bear with me: I'm a hack with little modern programming experience. |
Trent Gamblin
Member #261
April 2000
|
The only way it could crash is if airspeed_tape is invalid. Make sure it's loaded or created correctly by checking return values from al_load_bitmap and/or al_create_bitmap (or however you're loading that bitmap.) Posting more code would help us determine the problem.
|
BigGiantBrain
Member #8,769
June 2007
|
I tested for the existence of the airspeed_tape bitmap, and it exists. |
Trent Gamblin
Member #261
April 2000
|
Post more code.
|
BigGiantBrain
Member #8,769
June 2007
|
Is there a supporting #include required to support tinting? |
Trent Gamblin
Member #261
April 2000
|
No. Trent Gamblin said: The only way it could crash is if airspeed_tape is invalid. This is a true statement with one extra condition -- there may be an error somewhere else in your code that could cause it too.
|
BigGiantBrain
Member #8,769
June 2007
|
Very curious. Eliminating the tinted bitmap call allows it to run just fine...AND the bitmap exists. I'll keep digging...thanks |
Trent Gamblin
Member #261
April 2000
|
How are you determining that the bitmap "exists"?
|
BigGiantBrain
Member #8,769
June 2007
|
Two ways: First, I comment out only the al_draw_tinted_bitmap line, and the code runs, alters the existing bitmap, and shows it on the display. Second, I added this test: I tried substituting any of the other 6 clipped bitmaps, and they all generate the debug error. There's no doubt that they exist. Should it matter that they are all sub bitmaps? I thought I'd read somewhere in the docs that tint support required an include. |
Trent Gamblin
Member #261
April 2000
|
Ok, without seeing code I can't help anymore but BigGiantBrain said: I thought I'd read somewhere in the docs that tint support required an include. This doesn't really make sense. You'll understand why when you learn more about C (hint: feature support can't be turned on or off with an include, includes are used to tell the compiler it's ok to use a function named x with parameters y -- if you don't get a compile error, the include has nothing to do with it.)
|
BigGiantBrain
Member #8,769
June 2007
|
EDIT: Ok, problem solved. The code posted below is working, more or less. I was not properly locating objects on the underlying plane to benefit from the transparency. Thanks for the help. I'll go set up a dedicated test routine to get it working, so that if I can't figure it out I can post a short block of code. It won't do any good to post anthing now, as its a large program, and short of showing the bitmap creation lines, most is not relevant. I'll come back when I can better use your time...thanks. Here is a test which runs but does not tint: It prints a red square on the target bitmap. Note: this code loops endlessly...I use a breakpoint in the debugger to halt it to view the output. #include <allegro5/allegro.h> ALLEGRO_BITMAP *airspeed_tape = NULL; ALLEGRO_FONT *font = NULL; int main(int argc, char **argv) display = al_create_display(1280, 800); airspeed_tape = al_create_bitmap(1280, 800); al_draw_filled_rectangle(50,50,200,200,al_map_rgb(255,0,0)); float r =.5; ALLEGRO_COLOR transparent_color = al_map_rgba_f(a, a, a, a); al_set_target_backbuffer(display); al_destroy_bitmap(airspeed_tape); } |
Trent Gamblin
Member #261
April 2000
|
If you draw a transparent image over and over without clearing the backbuffer, it'll eventually turn solid.
|
Dizzy Egg
Member #10,824
March 2009
|
Hmmm...returning on the first loop...and this works does it?
---------------------------------------------------- |
Trent Gamblin
Member #261
April 2000
|
Hi Dizzy.
|
Dizzy Egg
Member #10,824
March 2009
|
Hi Trent, how's the duck platformer coming along?
---------------------------------------------------- |
Trent Gamblin
Member #261
April 2000
|
I'm sorry that's off topic. (but good)
|
Dizzy Egg
Member #10,824
March 2009
|
Off: cool, looking forward! On: Try this in a loop; clear screen, draw images on bitmap(buffer), draw buffer(bitmap) on screen, check to see if it's time to stop, if not, clear screen, draw images on bitmap(buffer), draw buffer(bitmap) on screen, check to see if it's time to stop, if not, clear screen, draw images on bitmap(buffer), draw buffer(bitmap) on screen, check to see if it's time to stop, if not, clear screen, draw images on bitmap(buffer), draw buffer(bitmap) on screen, check to see if it's time to stop, if no....if it IS, exit loop and then return.
---------------------------------------------------- |
|