Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DrSanent

OpenGL Gamma control in OpenGL

This topic is 5853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m trying to change the gamma for my game and I can''t find anything anywhere that will tell me how to do it. I''ve read some functions about DirectX but I don''t want to resort to that to change the gamma. Has anyone been able to accomplish this?

Share this post


Link to post
Share on other sites
Advertisement
your in luck, i just finnished coding a gamma control class ...


  

struct Ramp {
WORD r[256];
WORD g[256];
WORD b[256];
}

#define CLAMP(T) {if(T>255) T=255; else if(T<0) T=0;}

GammaControl::GammaControl()
{
ZeroMemory(&NewRamp,sizeof(Ramp));
ZeroMemory(&originalRamp,sizeof(Ramp));
}

GammaControl::~GammaControl()
{
SetDeviceGammaRamp(GetDC(hWnd),&originalRamp);
}

int GammaControl::SetGamma(float Gamma,HWND hWnd)
{
HDC dc = GetDC(hWnd);
GetGamma(hWnd);

float Brightness = 1.9f;
float Overbright = 2.f;
int f = 0;
for (int i=0 ; i<256 ; i++){
f = int(255 * pow ( (float)i/255.0 , 1/.987f ));
f = (f+Brightness) * Overbright;

CLAMP(f);

NewRamp.b[i] =
NewRamp.g[i] =
NewRamp.r[i] =
(WORD) (f<<8);
}

if(!SetDeviceGammaRamp(dc, &NewRamp)){
return 0;
}

return 1;
}

int GammaControl::GetGamma(HWND hWnd)
{
this->hWnd = hWnd;
GetDeviceGammaRamp(GetDC(hWnd),&originalRamp);
return 1;
}

int GammaControl::RestoreGamma()
{
SetDeviceGammaRamp(GetDC(this->hWnd), &originalRamp);
return 1;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!