Blending issues
alex Ioan
al_set_blender(ALLEGRO_ONE, ALLEGRO_ZERO, al_map_rgba(255, 255, 255, 255));

I cant seem to get this to work... if I want to draw transparent text shouldn't I just change the last 255 value ? Anyway this line won't work.... can't pass ALLEGRO color as int... searched the manual, found another syntax for that last parameter but it made the text not show up...

Trent Gamblin

The other parameter is the first not the last, and it's the blend mode. You want ALLEGRO_ADD there. To get transparency you change the last parameter to the alpha value then multiply the color components by it. It makes the most sense with floats:

al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA,al_map_rgba_f(1.0*0.75, 1.0*0.75, 1.0*0.75, 0.75));

alex Ioan

Error 1 error C2660: 'al_set_blender' : function does not take 4 arguments

Slartibartfast

Look at the code in your post, al_set_blender is a link. Click it and read the correct way to use al_set_blender.

alex Ioan

sorry, read that numerous times... but still can't figure out how it works :))
Tried examples code and other codes I found @ this forum, still does not work.

tried al_draw_text(font, al_map_rgba_f(0.25, 0.25, 0.25, 0.25), 100, 100,ALLEGRO_ALIGN_LEFT,"TEXT");

this works at least...

Arthur Kalliokoski

I'm not sure, but I think Trent's post was supposed to have an OR '|' in place of one of the commas, which would be 3 parameters.

Slartibartfast

Yes, that is the correct way.
al_set_blender sets the blending mode. The default is pre-multiplied alpha which means that the color al_map_rgba_f(0.25, 0.25, 0.25, 0.25) is actually full white that has the alpha turned down to 25%. If you wanted non pre-multiplied alpha you can also see how to do that in the al_set_blender page, and in that case you would get a dark grey with 25% alpha for these same values.

Once the blending mode is correct, you want to draw your text, which you can indeed do with al_draw_text, and if you want the text to have a certain color you'd put in the correct values for the color as per your blending mode.
If you use the same color with any of the text drawing functions (like al_draw_textf you will get the same result.

alex Ioan

so for text just use

al_draw_text(font, al_map_rgba_f(0.25, 0.25, 0.25, 0.25), 100, 100,ALLEGRO_ALIGN_LEFT,"TEXT");

what would be the difference between this and using a blender ?
and HOW the hell would that code look like since I still can't get it to work ;D

PS: drawing the text with that color works well only for white.... trying to get other pure color transparent is kinda hard...

Isn't there a way to only make ANY colored text an amount of % transparent ?

Trent Gamblin

Oops, I'm thinking a year ago. The correct format is:

al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);

alex Ioan

al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);

this makes images and text sorta transparent to each other... I mean when I crossover 2 bitmaps Its like they are both a bit transparent. Still that doesn't help me get faded text on black background :)

Trent Gamblin

To fade text, adjust the alpha in the al_draw_text command. Like you have above... not sure I understand what you want though. To just draw it transparent, use 0.x for all 4 colour parameters, to make it gradually fade, adjust the values from 1.0 to 0.0 gradually over time.

EDIT: And you want ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA not ONE, ONE.

alex Ioan

yea I got it now, it was ok in the first place

But anyway
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
works well... I mean it makes everything transparent to each-other
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); makes everything opaque

Thread #608175. Printed from Allegro.cc