Question about a function in Allegro 4.4
Walid Jabari

Hello, I know allegro 4.4 is outdated but we have to use it for a school project.

I can't figure out how to use the fade_in and fade_out functions. In this code :

I'm trying to make use of the fade_out(int speed) function in order to fade out from a green to a black screen, but it doesn't seem to be working properly.

Thank you for your help !


You can't, since you are probably not using 8 bit colour for your desktop colour depth.
This is an old "palette" effect which doesn't translate to non-palettized modes (e.g. 32 bit / 24 bit colour, even 15/6 bits) which are common today.

Walid Jabari

Okay, thank's for the reply.

What would be best way to fade in/fade out a bitmap in allegro 4.4 ?

Chris Katko

Allegro 4 can use 16/32-bit color.

Do you explicitly NEED 8-bit color?

Walid Jabari

I am just trying to fade in/fade out bitmaps to the screen.
The only constraint I have is to use allegro 4.4.2 instead of the more recent one.

I can't figure out how to make proper usage of the functions fade_in(const PALETTE p, int speed) and fade_out(int speed)

I just commented my code to allow a better understanding of what I'm trying to do

Thanks for the help :)

Edgar Reynaldo

You're not using 8-bit color, so there's no PALETTE.

You'll need to interpolate between the two colors yourself, and perform a manual fade.

1void Fade(int r1 , int g1 , int b1 , int r2 , int g2 , int b2 , double duration) { 2 3 double pct = 1.0; 4 int NFRAMES = 60*duration; 5 double dt = duration/NFRAMES; 6 double elapsed = 0.0; 7 8 for (int i = 0 ; i < NFRAMES + 1; ++i) { 9 double percent = (double)i/NFRAMES; 10 clear_to_color(screen , makecol(r1 + (r2-r1)*percent , 11 g1 + (g2-g1)*percent , 12 b1 + (b2-b1)*percent)); 13 if (keypressed()) { 14 break; 15 } 16 rest(dt*1000); 17 } 18}

Minor code update.

Chris Katko

Also, if you can use Allegro 5, use that instead. It's pretty much better for everything except super-retro games that run in DOS.

Walid Jabari

Thank you, I understand now.

Is it possible to apply the same thing with BITMAPS?

Edgar Reynaldo

I believe you can achieve transparent blending in Allegro 4 using set_trans_blender and draw_trans_sprite.

Walid Jabari

Yes!! it worked.
Thank you very much for your help

Thread #617365. Printed from