Tweak the brightness/gamma of the whole scene in OpenGL

落花浮王杯 提交于 2019-11-30 23:10:48

On win32 you can use SetDeviceGammaRamp to adjust the overall brightness / gamma. However, this affects the entire display so it's not a good idea unless your app is fullscreen.

The portable alternative is to either draw the entire scene brighter or dimmer (which is a hassle), or to slap a fullscreen alpha-blended quad over the whole scene to brighten or darken it as desired. Neither of these approaches can affect the gamma-curve, only the overall brightness; to adjust the gamma you need grab the entire scene into a texture and then render it back to the screen via a pixel-shader that runs each texel through a gamma function.

Ok, having read the updated question, what you need is a quad with blending set up to darken or brighten everything underneath it. Eg.

if( brightness > 1 )
{
    glBlendFunc( GL_DEST_COLOR, GL_ONE );
    glColor3f( brightness-1, brightness-1, brightness-1 );
}
else
{
    glBlendFunc( GL_ZERO, GL_SRC_COLOR );
    glColor3f( brightness, brightness, brightness );
}
glEnable( GL_BLEND );

draw_quad();

http://www.gamedev.net/community/forums/topic.asp?topic_id=435400 might be an answer to your question otherwise you could probably implement a gamma correction as a pixel shader

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!