I have problems with
SET GAMMA command
I want to correct gamma in the game. Simply to change brightness and contrast but SET GAMMA can't do this
If you look at the code of SET GAMMA then it becomes clear that this function
only reduce brightness
DARKSDK bool Constructor ( void )
{
...
m_iGammaRed = 255;
m_iGammaGreen = 255;
m_iGammaBlue = 255;
...
}
DARKSDK void SetGamma ( int iR, int iG, int iB )
{
...
for ( iColour = 0; iColour < 256; iColour++ )
{
// setup colours
ddgr.red [ iColour ] = wRed; // set red
ddgr.green [ iColour ] = wGreen; // set green
ddgr.blue [ iColour ] = wBlue; // set blue
// increment colours
wRed += ( WORD ) iR; // add red component
wGreen += ( WORD ) iG; // add green component
wBlue += ( WORD ) iB; // add blue component
}
// now that we have setup the gamma structure we can
// pass the info across to D3D and apply the changes
m_pD3DDevice->SetGammaRamp ( 0, D3DSGR_NO_CALIBRATION, &ddgr );
}
Function forms a
linear RAMP. And what about gamma?
I found good link
http://en.wikipedia.org/wiki/Gamma_correction
So if we change our function to:
DARKSDK void SetGamma ( int iR, int iG, int iB )
{
...
float recip_red = logf( iR / 255.f ) / logf( 0.5f ); //change logf( 0.5f) to constant -0.30102999566 if you want)
float recip_green = logf( iG / 255.f ) / logf( 0.5f ); //блин хрень еще та
float recip_blue = logf( iB / 255.f ) / logf( 0.5f );
...
for ( iColour = 0; iColour < 256; iColour++ )
{
ddgr.red [ iColour ] = (int) ( 65535 * pow( iColour / 255.f, recip_red));
ddgr.green [ iColour ] = (int) ( 65535 * pow( iColour / 255.f, recip_green));
ddgr.blue [ iColour ] = (int) ( 65535 * pow( iColour / 255.f, recip_blue));
}
...
m_pD3DDevice->SetGammaRamp ( 0, D3DSGR_NO_CALIBRATION, &ddgr );
}
YES! Now it's real gamma
imho
But there is one more problem. This function works only (I didn't see videocard wich support gamma in windowed mode) in fullscreen.
The DirectX function SetGammaRamp is useless for us in windowed mode, but what about GDI?
In constructor() we save current ramp and in the destructor() restore system ramp.
I compile an example where you can change gamma in fullscreen or in windowed mode.
And yes I know about contrast shader and about sprite/plane over viewport but these decisions add integrated approach to the project.
It seems to me that I have missed something and there is a simple decision for brightness and contrast change in DBPro. So need your help