Final solution to change gamma in Irrlicht application using Windows API (don't forget to add User32.lib (for GetDC) and Gdi32.lib (for SetDeviceGammaRamp and GetDeviceGammaRamp) into Extra libraries)
Code: Select all
bool SetGamma(float gamma)
{
WORD *ramp = new WORD[256 * 3];
for (int i = 0; i < 3; i++)
{
int min = 256 * i;
int max = min + 256;
for (int j = min; j < max; j++)
ramp[j] = pow((float)((j % 256) / 256.0), gamma) * 65536;
}
if (SetDeviceGammaRamp(GetDC(NULL), ramp)) return true;
else return false;
}
float GetGamma()
{
WORD *ramp = new WORD[256 * 3];
GetDeviceGammaRamp(GetDC(NULL), ramp);
float gamma = 1.0;
float Csum = 0.0;
int Ccount = 0;
int min = 256;
int max = min + 256;
for (int j = min; j < max; j++)
{
if (j != 0 && ramp[j] != 0 && ramp[j] != 65536)
{
double B = (j % 256) / 256.0;
double A = ramp[j] / 65536.0;
float C = (float) ( log(A) / log(B) );
Csum += C;
Ccount++;
}
}
gamma = Csum / Ccount;
return gamma;
}
Big thanks to zola for showing the way! God bless you!
Code GetGamma() partially from http://www.monkeybreadsoftware.de/realb ... 03_1.shtml