Tinting a screen black and white

Started by GarageGothic, Sat 03/07/2004 14:17:47

Previous topic - Next topic

GarageGothic

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.

Scorpiorus

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.

GarageGothic

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.

Scorpiorus

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.

Ishmael

A big transpearent grey GUI..? Atleast it should work partially, in theory, methinks...
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

scotch

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.

GarageGothic

Ok, thanks guys - I didn't think it was possible either, just wanted to make certain before I dropped it altogether.

Hollister Man

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.
That's like looking through a microscope at a bacterial culture and seeing a THOUSAND DANCING HAMSTERS!

Your whole planet is gonna blow up!  Your whole DAMN planet...

GarageGothic

Ah, thanks. Too bad I'm using 32-bit

Barbarian

#9
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/
Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

scotch

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..

Gilbert

#11
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

Hollister Man

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. ;)
That's like looking through a microscope at a bacterial culture and seeing a THOUSAND DANCING HAMSTERS!

Your whole planet is gonna blow up!  Your whole DAMN planet...

Gilbert

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.

GarageGothic

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?

scotch

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.

Hollister Man

Actually, Gilbot, I typed that before you posted your edit, and submitted it thrity seconds later or so.  sorry bout that
That's like looking through a microscope at a bacterial culture and seeing a THOUSAND DANCING HAMSTERS!

Your whole planet is gonna blow up!  Your whole DAMN planet...

Scorpiorus

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.

SMF spam blocked by CleanTalk