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?
If you use 8 bit color you can cycle a palette.
Are blender functions of help here? Not sure on this as I haven't used them myself as yet.
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?
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.
I guess you mean a rainbow effect like:
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.
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...
yes but no rainbow
1 | int y=0; |
2 | |
3 | float red =0.0 , red_inc = 0.5 ; |
4 | |
5 | BITMAP *backgroung; |
6 | |
7 | background = create_bitmap( SCREEN_W , SCREEN_H ); |
8 | |
9 | for( y = 0 ; y < SCREEN_H ; y +=1 ){ |
10 | |
11 | red=red + inc; |
12 | if( red > 255 ){ |
13 | red = 255; |
14 | inc = -inc; |
15 | } |
16 | |
17 | hline( background, 0 , y , SCREEN_W , makecol( (int)red , 0 , 0 ) ); |
18 | } |
19 | |
20 | blit( background , screen_buffer , 0 , 0 , 0 , 0 , SCREEN_W , SCREEN_H ); |
With this there will be no rainbow.
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.
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.
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.
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.
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); }
ok i'll try that...