Fading
Neil Black

How can I do a fade in or fade out when I'm not using a palette? Also, how can I do a day/night cycle where the screen slowly darkens to night when I'm not using a palette?

gnolam

The easiest way is to draw a transparent black rectangle over the screen (buffer).

int alpha = 128; //arbitrary value for demonstration purposes

drawing_mode(DRAW_MODE_TRANS);
set_trans_blender(0, 0, 0, alpha);

rectfill(buffer, 0, 0, buffer->w, buffer->h, makecol(0, 0, 0));

blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

Quote:

Also, how can I do a day/night cycle where the screen slowly darkens to night when I'm not using a palette?

Depends on what kind of effect you're after. For a simple "everything turns darker" effect, see the code snippet above.

Neil Black

Okay, in 16 bit mode I thought there wasn't an alpha value. I should have mentioned that I'm using a 16 bit color depth. Will that still work?

And the day/night cycle needs to fade to night, where the colors are darker and seem more bluish, and then back to day. I could have separate tiles for day and night, but there would be problems during the transition. Whatever I do has to be fast enough to run during game play.

Kauhiz
Quote:

Okay, in 16 bit mode I thought there wasn't an alpha value.

There isn't, that's why you have to supply it separately. In 32bpp you could have the alpha values stored in the bitmap.

Dustin Dettmer
const int cycles = 60 * 3;
for(int i = 0; i <= cycles; i++) {
 conf.beginScene();
 drawGame();
 Bitmap::rect(0, 0, 640, 480, Tint(1, 1, 1, float(i) / cycles);
 conf.flip();
}

Neil Black

okay, dustin dettmer, you have several things I've never seen before in that code snippet, like Tint(...). is that an allegro function or just something you wrote that does what gnolam said? I also don't know what conf.beginScene() or
conf.flip() do. But I do understand the general idea... I think. I'd better do some experimenting.

GullRaDriel

It looks like openlayer thing.

Neil Black

Openlayer? oh crap, more things-I-don't-understand-but-need-to! I thought I was through with that after I learned to tie my own shoes when I was 17 ;)

Dustin Dettmer

Its actually from the Thing library. Which will soon be merged with OL (aka once I get some free time).

Steve Terry

In 16-bit you can basically do a fast fade by packing two bytes into a 32-bit register. Here is the code I used:

1void Fade16(BITMAP *src, BITMAP *dest, int frame, int x, int y){
2 unsigned long* read;
3 unsigned long write;
4 register unsigned long c1, c2;
5 BITMAP *tmp = create_bitmap_ex(16, src->w, src->h);
6 int i, j;
7 int wid = src->w;
8 acquire_bitmap(tmp);
9 for(j = 0; j < src->h; ++j){
10 read = (unsigned long*)src->line[j];
11 write = bmp_write_line(tmp, j + y);
12 for (i = wid; i; i-=2){
13 // get two pixels;
14 c1 = *read++;
15 c2 = c1 & 0x7E0F81F;
16 c1 &= 0xF81F07E0;
17 // c1 / 32 * frame... then mask out the color components...
18 c1 = (((c1 >> 5) * frame) & 0xF81F07E0);
19 // c2 * frame / 32... then mask out the color components...
20 c2 = (((c2 * frame) >> 5) & 0x07E0F81F);
21 bmp_write32(write + x, ( c1 | c2 ));
22 write+=4;
23 }
24 }
25 bmp_unwrite_line(tmp);
26 release_bitmap(tmp);
27 blit(tmp, dest, 0, 0, x, y, tmp->w, tmp->h);
28 destroy_bitmap(tmp);
29}

Well maybe not... I think I had a better function that didn't require a temporary bitmap... but meh?

Neil Walker
Neil Black

Gnolam's method seems to be the easiest, so I tried it first. Works perfectly! Thanks guys

Thread #589913. Printed from Allegro.cc