Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: GarageGothic on Sat 03/07/2004 14:17:47

Title: Tinting a screen black and white
Post by: GarageGothic on Sat 03/07/2004 14:17:47
ThisÃ,  is probably a dumb question, but I have to ask - is there any way to "tint" the screen black and white (you know, like the Sam & Max film noir mode)? It seems that the TintScreen function only is additive when it comes to color. I suppose you would need to set it to (-100, -100, -100), if it was possible to use negative values. Or would that make the screen black? I'm confusing myself here.
Title: Re: Tinting a screen black and white
Post by: Scorpiorus on Sat 03/07/2004 14:26:27
For the HiColor mode you can do RawDrawImageTransparent to blend a black or white fullscreen-sized sprite with the background. Another possibility is to have a black/white GUI and set its transparecy accordingly (SetGUITransparency) if you want it to be an overlay.
Title: Re: Tinting a screen in grayscale
Post by: GarageGothic on Sat 03/07/2004 14:32:16
I think you misunderstand my question (or I misunderstand your reply) - I didn't mean black OR white, but black AND white, as in black and white movies, monochrome, grayscale. I don't want to fade to black or white, just turn the background from color to grayscale. It's for a general effect (when pausing the game, or when reading documents in close-ups) so using a different background frame isn't really a solution either.
Title: Re: Tinting a screen black and white
Post by: Scorpiorus on Sat 03/07/2004 14:38:02
Ah, sorry. I don't think it's possible to achieve with scripting only since we can't read a colour from the screen. I'm not sure but think that the flashlight plugin has such a filter you are talking about.
Title: Re: Tinting a screen black and white
Post by: Ishmael on Sat 03/07/2004 14:44:40
A big transpearent grey GUI..? Atleast it should work partially, in theory, methinks...
Title: Re: Tinting a screen black and white
Post by: scotch on Sat 03/07/2004 14:47:39
No, that would have a similar effect to turning down the contrast on your TV, everything would just get more grey instead of losing colour saturation, which is what GG wants.
I think the only way to acheive this would be a plugin as Scorpius says.
Title: Re: Tinting a screen black and white
Post by: GarageGothic on Sat 03/07/2004 14:49:44
Ok, thanks guys - I didn't think it was possible either, just wanted to make certain before I dropped it altogether.
Title: Re: Tinting a screen black and white
Post by: Hollister Man on Sat 03/07/2004 15:45:52
If you are using 256 color it can be done.  Using the setpalRGB, just set every palette slot (using a while loop) to have equal parts of R, G and B (you might want to average the R, G and B of each slot).  I used a similar concept to make a fade to green effect.  When you're done, restore the original values of the colors.
Title: Re: Tinting a screen black and white
Post by: GarageGothic on Sat 03/07/2004 15:47:59
Ah, thanks. Too bad I'm using 32-bit
Title: Re: Tinting a screen black and white
Post by: Barbarian on Sat 03/07/2004 18:23:53
I'm not sure, but the wonderful FLashlight Plugin by a-v-o (as Scorpiorus already suggested) might be able to do what you want as it has the ability to tint and/or darken the whole screen in various colors too. If you d-load it, read the tutorial.txt that comes with it.

http://a-v-o.selfhost.de/ags/flashlight/
Title: Re: Tinting a screen black and white
Post by: scotch on Sat 03/07/2004 21:22:41
I don't actually think you can do it with that plugin..
I made a b&w plugin, but it's probably too slow to be usable in 640x480 and I'm not sure if it could be done any faster I'm afraid.  But you could give it a try: http://www.agagames.com/scotch/ags_bandw.dll
it provides
GrayscaleOn();
GrayscaleOff();
IsGrayscaleOn();

It only works in proper 32 bit mode atm, not 16 or 24..
Title: Re: Tinting a screen black and white
Post by: Gilbert on Mon 05/07/2004 03:22:22
Quote from: Hollister Man on Sat 03/07/2004 15:45:52
If you are using 256 color it can be done.Ã,  Using the setpalRGB, just set every palette slot (using a while loop) to have equal parts of R, G and B (you might want to average the R, G and B of each slot).Ã, 

No, don't use SetPalRGB(), especially in circumstances like this, that probably all 256 slots need to be changed at once. The reason was each call to SetPalRGB() updates the screen once, that made it updating the screen hundreds of times in one game loop (as this function only alters one colour slot at one time), which can be EXTREMELY slow with some computers (trust me, I had encountered this before). The best way is to mess with the palette[] variables, then call UpdatePalette() to update the screen at once.

Example:

First you need some variables to hold the original palette (so you can restore it back later).
color tmppal[256];

If you want to turn the screen B/W (I only do instant effect here, if you want gradual change, I can also post it here):
int i,tcolor;
while(i<256){
tmppal.are=palette.are;//save the palette
tmppal.g=palette.g;
tmppal.b=palette.b;
tcolor=(palette.are+palette.g+palette.b)/3;
palette.are=tcolor;
palette.g=tcolor;
palette.b=tcolor;
i++;
}
UpdatePalette();


If you want the colours back, just do:
int i;
while(i<256){
palette.are=tmppal.are;
palette.g=tmppal.g;
palette.b=tmppal.b;
i++;
}
UpdatePalette();



EDIT: Foolish txt style correcting, it's changing all my .R into .are
Title: Re: Tinting a screen black and white
Post by: Hollister Man on Mon 05/07/2004 03:29:54
That's really what I meant, GB, I forgot exactly how I did it.    BTW: Please put you code in [ code ] [ /code ]  look at the last part of your script  palette.are is not acceptable. ;)
Title: Re: Tinting a screen black and white
Post by: Gilbert on Mon 05/07/2004 03:38:57
Quote from: Hollister Man on Mon 05/07/2004 03:29:54
Ã,  BTW: Please put you code in [ code ] [ /code ]Ã,  look at the last part of your scriptÃ,  palette.are is not acceptable. ;)

Because I don't want to, and you should had read my edit.
Title: Re: Tinting a screen black and white
Post by: GarageGothic on Mon 05/07/2004 09:46:45
Thank you very much scotch, I'll look into it when I get back home. Didn't even know there was a black and white plugin available. I don't have any animation on the screen while in b&w mode, only guis (only thing moving is the mouse cursor). Do you still think it will be too slow?
Title: Re: Tinting a screen black and white
Post by: scotch on Mon 05/07/2004 15:29:25
Well, on my system, which is 2ghz, the framerate falls to about 35-40 fps (in 640x480x32), which is fine.. but if you're aiming at low end systems <500mhz perhaps, then it would be uncomfortably slow for extended periods.  Animation and  other things shouldn't make a difference to the speed.

I may be able to optimise it a little bit, if you decide to use it, and I should make it support other colour depths.
Title: Re: Tinting a screen black and white
Post by: Hollister Man on Mon 05/07/2004 16:18:58
Actually, Gilbot, I typed that before you posted your edit, and submitted it thrity seconds later or so.  sorry bout that
Title: Re: Tinting a screen black and white
Post by: Scorpiorus on Fri 09/07/2004 22:09:37
QuoteNo, don't use SetPalRGB(), especially in circumstances like this, that probably all 256 slots need to be changed at once. The reason was each call to SetPalRGB() updates the screen once, that made it updating the screen hundreds of times in one game loop (as this function only alters one colour slot at one time), which can be EXTREMELY slow with some computers (trust me, I had encountered this before).
A very good point - I think it should be mentioned in the manual as to why it's better to alter palette[].xxx variables and then do UpdatePalette to apply the changes in one go.

QuoteWell, on my system, which is 2ghz, the framerate falls to about 35-40 fps (in 640x480x32), which is fine.. but if you're aiming at low end systems <500mhz perhaps, then it would be uncomfortably slow for extended periods.
In regards to the optimization, in this particular case if the game is paused (there are no characters moving around) we could create a grayscaled bitmap just once and then blit it (or maybe even RawDraw) onto the background.