Gamma correction?
Hello, I was wondering if there was any gamma correction feature in OpenGL that you can invoke in your app. Is there any, or is that just a hardware interface issue?
If there is one, is there also one for hue, contrast, and so on?
Thanks in advance.
I don''t think there is a gamma correction included in core OpenGL. However under Windows you can use the SetDeviceGammaRamp() function.
SetGammaDeviceRamp() manipulates the frame buffer directly which will mess it up beyond all repair unless you use some other method (provided that you modify the gamma a lot).
The only real way to do it is by loading the textures and modifying their brightness directly (my multiplying each pixel with some gamma modifier). At this point you can control the actual output and, if necessary, run the textures through some filters and stuff to reduce distortion. Another alternative would be to rely on the user to modify the monitor''s gamma and brighness manually.
This may seem like a difficult thing to do (and it''s no fun, granted), but it''s kinda difficult to reach some nice-looking result using a different approach.
The only real way to do it is by loading the textures and modifying their brightness directly (my multiplying each pixel with some gamma modifier). At this point you can control the actual output and, if necessary, run the textures through some filters and stuff to reduce distortion. Another alternative would be to rely on the user to modify the monitor''s gamma and brighness manually.
This may seem like a difficult thing to do (and it''s no fun, granted), but it''s kinda difficult to reach some nice-looking result using a different approach.
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
quote:
Original post by Crispy
SetGammaDeviceRamp() manipulates the frame buffer directly which will mess it up beyond all repair unless you use some other method (provided that you modify the gamma a lot).
Actually, SetDeviceGammaRamp() does *not* manipulate the frame buffer, but the values your video card sends to the monitor. Whatever your gamma ramp values are, your frame buffer content stays the same (notice that if you make a screenshot with glReadPixels() your screenshot will not be affected by the gamma).
From the MSDN:
The gamma ramp is specified in three arrays of 256 WORD elements each, which contain the mapping between RGB values in the frame buffer and digital-analog-converter (DAC) values.
quote:
The only real way to do it is by loading the textures and modifying their brightness directly (my multiplying each pixel with some gamma modifier). At this point you can control the actual output and, if necessary, run the textures through some filters and stuff to reduce distortion. Another alternative would be to rely on the user to modify the monitor''s gamma and brighness manually.
Unless you''re doing very simple things (just displaying images, with no lighting, blending or any modulation), you won''t get the same result as a proper gamma correction, for basic arithmetic reasons. Let''s say you want to add two textures together, with a gamma ramp, you get :
(tex0 + tex1)^g
But if you try to pre filter your textures, you''ll get something like :
tex0^g + tex1^g''
Which is not the same. You could twist the g and g'' values to get the same value as a proper gamma correction, but you won''t be able to get correct results for all your operations.
I really fail to see why you wouldn''t use SetDeviceGammaRamp().
Prosper/LOADED: I'm afraid I'm going to have to give in on this one
. I was replying from school and was in a bit of a rush so I evidently speculated a little (read: didn't have time to check).
Why not use SDGR()? Have you used it? I have and the outcome allowed for a lot of distortion to appear. I didn't delve into it too much, but I guess there's a reason why it's not officially recommended. Altering your texture brighness directly gives you much better results.
edit: I'm pretty tired right now so you may bash me as hard as you see fit
. No, really - this is out of personal experience. It worked fine for me...
[edited by - crispy on May 12, 2003 4:25:21 PM]

Why not use SDGR()? Have you used it? I have and the outcome allowed for a lot of distortion to appear. I didn't delve into it too much, but I guess there's a reason why it's not officially recommended. Altering your texture brighness directly gives you much better results.
edit: I'm pretty tired right now so you may bash me as hard as you see fit

[edited by - crispy on May 12, 2003 4:25:21 PM]
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
I've only had three problem when using setDeviceGammaRamp...
1)
it will hang some pcs.. so make it an option before it happenes, and make sure you check that getDeviceGammaRamp works first.
2)
windows XP will check the gamma ramp you pass in, so it makes sure it's actually going to show anything.. unfortunatly, it's a bit harsh here... eg, the max you can under/overbright the gamma ramp is around 0.5-3.6x.
3)
the values you set are saved as defaults loaded with setDeviceGammaRamp... I do remember researching this and finding something in the VS DDK that got around this.. but that was a bit much
Otherwise it's all good.
Just note, though, that the values are not between 0 and 255, they are between 0 and 65536.
There are some very nice effects that can be done with direct gamma ramp manipulation. A personal favorite of mine is IR goggles effects...
| - Project-X - my mega project.. close...
- | - adDeath - | - email me - |
[edited by - RipTorn on May 13, 2003 5:45:04 AM]
1)
it will hang some pcs.. so make it an option before it happenes, and make sure you check that getDeviceGammaRamp works first.
2)
windows XP will check the gamma ramp you pass in, so it makes sure it's actually going to show anything.. unfortunatly, it's a bit harsh here... eg, the max you can under/overbright the gamma ramp is around 0.5-3.6x.
3)
the values you set are saved as defaults loaded with setDeviceGammaRamp... I do remember researching this and finding something in the VS DDK that got around this.. but that was a bit much

Otherwise it's all good.
Just note, though, that the values are not between 0 and 255, they are between 0 and 65536.
There are some very nice effects that can be done with direct gamma ramp manipulation. A personal favorite of mine is IR goggles effects...
| - Project-X - my mega project.. close...

[edited by - RipTorn on May 13, 2003 5:45:04 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement