Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Question about a function in Allegro 4.4

Credits go to Edgar Reynaldo for helping out!
This thread is locked; no one can reply to it. rss feed Print
Question about a function in Allegro 4.4
Walid Jabari
Member #16,839
April 2018

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 : https://gist.github.com/walidjabari/c2c58f27ecb826e83c6eba7ab5e1f79b

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 !

Polybios
Member #12,293
October 2010

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
Member #16,839
April 2018

Okay, thank's for the reply.

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

Chris Katko
Member #1,881
January 2002
avatar

Allegro 4 can use 16/32-bit color.

Do you explicitly NEED 8-bit color?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Walid Jabari
Member #16,839
April 2018

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
https://gist.github.com/walidjabari/c2c58f27ecb826e83c6eba7ab5e1f79b

Thanks for the help :)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

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.

#SelectExpand
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}

EDIT
Minor code update.

Chris Katko
Member #1,881
January 2002
avatar

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.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Walid Jabari
Member #16,839
April 2018

Thank you, I understand now.

Is it possible to apply the same thing with BITMAPS?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Walid Jabari
Member #16,839
April 2018

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

Go to: