Hello Guest

How can I tint the screen or whatever I'm about to draw?

  • 11 Replies
  • 12632 Views
How can I tint the screen or whatever I'm about to draw?
« on: September 08, 2009, 19:26:53 »
I know with glColor4f I can make things darker, or semi-transparent, but if I want to make them lighter? Or change the saturation?

*

Kai

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #1 on: September 08, 2009, 20:13:55 »
Hi,

Quote
I know with glColor4f I can make things darker, or semi-transparent, but if I want to make them lighter? Or change the saturation?
Well, with glColor you specify the color in RGBA-space of everything you draw afterwards. The drawn geometry then receives the specified color (as well as texturing if enabled) and will be blended (if enabled) with what is already present in the color buffer.
I do not exactly know what you mean with "making things darker and lighter".
If by that you mean to transform the values of what is already in the color buffer, then use blending (draw a fullscreen grid of whatever color is appropriate (gray if you want to make things darker)). This is the simplest way but has very many limitations as to which functions can be applied on the source- and destination color.
If you desire more sophisticated "post-processing" effects, then you should go with custom fragment shaders.
You would then sample the values in the color-buffer (as a texture) and apply any function on them to produce the final color. (like a HLS <-> RGB transformation to change saturation)

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #2 on: September 08, 2009, 20:34:49 »
So basicly there's no function that allows this? I have to call more than one function to create this effect? I forgot to mention, it's for a 2D game (if that changes anything)

*

Kai

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #3 on: September 08, 2009, 20:41:37 »
Quote
So basicly there's no function that allows this? I have to call more than one function to create this effect? I forgot to mention, it's for a 2D game (if that changes anything)
There is no OpenGL function/entry point like "glSaturateScreen(float saturation)" that allows this, although it would be a nice extension :-) (as if there are not enough extensions anyways).
You have to implement it on your own via blending or fragment shader.

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #4 on: September 08, 2009, 20:55:16 »
What about something like glColor(2, 2, 2) where it usually accepts 1 as the max, where 1 is the original source color, but up to 2, where 2 is 255 of that color?

Say, if I have a green tree and paint it after glColor(0, 0, 0), I will only see a black shadow of that tree.  Now I want something like glColor(2, 2, 2) which would make the same but white (or glColor(1.5f, 1.5f, 1.5f) that would make it whiter than original but not completely white). No function in gl for that either? I know how to do it using blend, but I thought it might be slower that way, and that maybe gl came with a function for that already...

*

Kai

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #5 on: September 08, 2009, 21:07:48 »
Quote
What about something like glColor(2, 2, 2) where it usually accepts 1 as the max, where 1 is the original source color, but up to 2, where 2 is 255 of that color?
Hm, I thought I knew what you are up to, but I'm completely puzzled now :-).
You mean glColor(2, 2, 2) would be:
- If used as the source color of a geometry, the resulting fragments will affect the destination color of the pixel in the color buffer as follows: dst' = RGB(2 * dst.r, 2 * dst.g, 2 * dst.b) ?
So you want to make the destination color lighter (not darker)?
With glColor this is not possible, as far as I know, because of the [0, 1]-clamping.
There is an extension that allows floating-point colors, but I don't know whether glColor would clamped anyways. I usually did these things with shaders.

Quote
if I have a green tree and paint it after glColor(0, 0, 0), I will only see a black shadow of that tree.  Now I want something like glColor(2, 2, 2) which would make the same but white (or glColor(1.5f, 1.5f, 1.5f) that would make it whiter than original but not completely white)
Hum... I'm sorry, but I think you have to explain more thoroughly what you want to do.

If you use glColor without blending, the drawn geometry will have exactly that color (without lighting, texturing, etc.) if blending is disabled.
If blending is enabled, it depends on the blending function.

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #6 on: September 09, 2009, 00:50:27 »
Quote
With glColor this is not possible, as far as I know, because of the [0, 1]-clamping.
Yes, that's what I said. That's why I said "something like", "something equivalent".

Quote
So you want to make the destination color lighter (not darker)?
Exactly

I really have almost no knowledge at all of GL... don't know what "color of a geometry" or "resulting fragments" mean >_>

Note: it's not just the whole screen I wanna tint, I also wanna be able to apply it to

RPG Maker 2003, an application to create RPGs, had a tint function. Pretty much exactly what I wanna do. Here are some screenshots, hope they help understand =/

Normal color:



Tint at 150% (equivalent to 1.5f):



Tint at 200% (equivalent to 2f)



These are just examples, I want to be able to control RGB separatedly, too. Note that 200% is really pure white. So the function for 100% to 200% would be different than the one from 0 to 100%. The one from 0% to 100% would behave exactly like glColor, so for those cases, glColor suits me.

Anyhow, it seems this can't be done with just one function, so maybe it can be done with blend, and I'll have to learn about that (because I trully have almost no knowledge of GL)

You mean glColor(2, 2, 2) would be:
- If used as the source color of a geometry, the resulting fragments will affect the destination color of the pixel in the color buffer as follows: dst' = RGB(2 * dst.r, 2 * dst.g, 2 * dst.b) ?

Yes, that's what I want. Sort of, anyways.

After checking out glBlendFunc, I can't come up with anything that works fine without drawing the image more than once.
« Last Edit: September 09, 2009, 01:56:26 by lainmaster »

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #7 on: September 09, 2009, 12:32:50 »
Try look at the second post here: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=120353
I think its similar to what you want to do. Basically you just draw a big quad over the entire screen and change the color to produce an effect. It probably won't look perfect, but should give you a place to start.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #8 on: September 09, 2009, 12:45:22 »
And if I only want to tint an specific image and not the whole screen, and that image has transparent areas? I'd have to create a mask, right? Won't that bring the FPS down?

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #9 on: September 10, 2009, 12:27:26 »
It is possible you could also get the effect you need by drawing the image once normally and then again with a different color/blending mode on top of the first draw, but you might have to implement some pixel shaders that do what you need.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #10 on: September 10, 2009, 12:53:19 »
I just read an article on shaders, looks too complicated for now. I get how the color/blending would work, more or less, but I really rather keep the FPS as high as possible, so my game has compatibility with old computers; graphics aren't 100% relevant to my MMO RPG. (Al least the first version, I'll have to add that in the future, but it's not a priority)

Thanks for all the patience and help =)

Re: How can I tint the screen or whatever I'm about to draw?
« Reply #11 on: September 10, 2009, 15:51:17 »
You may be asking for an alpha texture : http://lwjgl.org/forum/index.php/topic,2918.0.html
Is that helping ?