rendering a fading background
Frank Drebin

is there a way to create a background (every game cycle) that fades from one color to an other?
i think you have to write a loop for every pixel then but that would be damn slow...
or is there a better way for doing this?

Trent Gamblin

If you use 8 bit color you can cycle a palette.

HardTranceFan

Are blender functions of help here? Not sure on this as I haven't used them myself as yet.

Frank Drebin

i'm not usgin 8bit mode but perhaps the blender-functions are what i'm looking for...
perhaps set_screen_blender ? anybody knows how to use them?

Archon
Quote:

is there a way to create a background (every game cycle) that fades from one color to an other?

I'd have to suggest OpenGL as you can easily glColor the corners of your background to whatever you like - and it's fast.

Otherwise, look into software blending.

Audric

I guess you mean a rainbow effect like:
turrican2-6.png
You can try to loop a vertical series of hline()

The speed of hline() is probably driver-dependant. If the result is not fast enough, pre-compute the rainbow on a BITMAP and blit it, hoping for a fast memory copy.

Frank Drebin

ok i'm not using opengl. so what about software blending?

[edit]
yes but no rainbow, the fading should be smooth!
ok i could precompute the image on a bitamp and then blit from that bitmap to the screen - but with maps of 1280*960 pixel (or even bigger) this would be a lot of memory...

GullRaDriel
Quote:

yes but no rainbow

1int y=0;
2 
3float red =0.0 , red_inc = 0.5 ;
4 
5BITMAP *backgroung;
6 
7background = create_bitmap( SCREEN_W , SCREEN_H );
8 
9for( y = 0 ; y < SCREEN_H ; y +=1 ){
10 
11red=red + inc;
12if( red > 255 ){
13red = 255;
14inc = -inc;
15}
16 
17hline( background, 0 , y , SCREEN_W , makecol( (int)red , 0 , 0 ) );
18}
19 
20blit( background , screen_buffer , 0 , 0 , 0 , 0 , SCREEN_W , SCREEN_H );

With this there will be no rainbow.

Audric

smooth? As long as you compute a different (theoric) color for each line, smoothness will ultimately depend on the screen's color depth. OpenGL will display exactly as many colors as software drawing, no more, no less.
Anyway, you can choose the color for each line yourself, to adapt to your color depth.

edit: Yep, I meant mathematical interpolation between two colors, like Gullradriel shows for #000000 to #FF0000. The Turrican screenshot I linked is a 256 color GIF, but the actual ingame rainbow has 12bit color depth.

Fladimir da Gorf
Quote:

but with maps of 1280*960 pixel (or even bigger) this would be a lot of memory...

Is 4.5 MB a lot of memory? Not these days. Though just using hline to render the background over and over could possibly be even faster, as it's more cache-efficient.

Frank Drebin

ok i think a nice way would be to have a "precomputed" bitmap that is 10*MAP_HEIGHT and blit this for MAP_WIDTH/10 times.
this way i would save some memory.

Audric

You can even try to store it as a single line, 1x960, and stretch_blit() it across the whole screen's width.
This technique is sometimes used for web pages.

Dustin Dettmer
int col1, col2;
int steps = 60 * 5; // about 5 seconds long

for(int i = 0; i < steps; i++) {
 int col = makecol((getr(col1) * (steps - i) + getr(col2) * i) * 255 / steps,
            (getg(col1) * (steps - i) + getg(col2) * i) * 255 / steps,
            (getb(col1) * (steps - i) + getb(col2) * i) * 255 / steps);

 vsync();
 rect(screen, 0, 0, SCREEN_W, SCREEN_H, col);
}

Frank Drebin

ok i'll try that...

Thread #589201. Printed from Allegro.cc