Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Blending issues

This thread is locked; no one can reply to it. rss feed Print
Blending issues
alex Ioan
Member #12,015
June 2010

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
Member #261
April 2000
avatar

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
Member #12,015
June 2010

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

Slartibartfast
Member #8,789
June 2007
avatar

alex Ioan
Member #12,015
June 2010

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
Second in Command
February 2005
avatar

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.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Slartibartfast
Member #8,789
June 2007
avatar

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
Member #12,015
June 2010

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
Member #261
April 2000
avatar

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

al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);

alex Ioan
Member #12,015
June 2010

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
Member #261
April 2000
avatar

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
Member #12,015
June 2010

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

Go to: