Why use the Gamma Control feature in DDraw to fade out? There are two main reasons: the first is because it is simple; the second is that by using gamma fade, you will not lose any information stored on the main surface.
In that case, there are some inconspicuous little things we must pay attention to before implementing this technology. First of all, your main surface must be 16Bit or higher, and the second is that this fade can only be done on your main surface because it is adjusting the gamma setting of your graphics card.
Let's think about this: include a structure ddgammaramp in the DirectDraw Library. This structure consists of 3 arrays of 256 words, Red,green and blue respectively. For example:
typedef struct DDGAMMARAMP
{
WORD red[256];
WORD green[256];
WORD blue[256];
}DDGAMMARAMP,FAR *LPDDGRAMMARAMP;
This structure holds the current gamma setting for our display card. So, to declare a few variables used in our program.
Initialize gamma control to apply
Lpdirectdrawgammacontrol Lpddgammacontrol = NULL;
This is the slope value we will revise (ramp)
Ddgammaramp Ddgammaramp;
This structure is used to save the original gamma value to restore our gamma value after fading out
Ddgammaramp Ddgammaold;
Having done this, we need to find out if the display supports gamma control (although DX will simulate it with software if the graphics hardware does not support it), query the main surface:
Lpddsprimary->queryinterface (Iid_idirectdrawgammacontrol, (void * *) & Lpddgammacontrol);
Then see if the current gamma setting for the video card is correct, and then store it in the ddgammaold structure.
Lpddgammacontrol->getgammaramp (0,&ddgammaold);
Let's do this and save the value into the DDGAMMARAMP structure so that we can modify its value:
Lpddgammacontrol->getgammaramp (0,&ddgammaramp);
Now unless a user changes the gamma setting on their computer, you should increase the value of your ddgammaramp structure to the NO. 256. Now, because each red,green and blue value can be any value from 0 to 65535, we don't want to change the value to 1. So I decided to write down the code as fast as possible to put all 256 values to 0 and then refresh the screen every time. Here is the code implementation: (Some of this is not clear, attached to the original:
Now unless a user changes the values of the "the" gamma on their computer the values should go up as to reach the 256th value I n your ddgammaramp structure. Now because each value of Red, Blue and Green can is anywhere from 0 to 65535 we wouldn ' t want to decrement our values by 1. Instead I decided to make the code as fast as possible I set all 256 values to 0 and update the screens after each. Here's how the code looks)
for (int blackloop=0;blackloop<256;blackloop++)
{
If a value is greater than 0, set it to 0.
if (Ddgammaramp.red[blackloop] > 0)
{
Set the current value of ddgammaramp.red to 0.
ddgammaramp.red[blackloop]=0;
Now let's update our primary
Lpddgammacontrol->setgammaramp (0, &ddgammaramp);
Surface with the new gamma setting
}
This program is a bit too fast, so let it slow down a little bit?
Sleep (1);
if (Ddgammaramp.green[blackloop] > 0)
{
Sets the value of the current Ddgammaramp.yellow to 0.
ddgammaramp.green[blackloop]=0;
Lpddgammacontrol->setgammaramp (Ddsgr_calibrate, &ddgammaramp);
}
Sleep (1);
if (Ddgammaramp.blue[blackloop] > 0)
{
Sets the value of the current Ddgammaramp.blue to 0.
Ddgammaramp. blue [blackloop]=0;
Lpddgammacontrol->setgammaramp (Ddsgr_calibrate, &ddgammaramp);
}
Sleep (1);
}//End
Now that the fade is complete, we need to restore all the original gamma values, otherwise the screen will always be black:
Lpddgammacontrol->setgammaramp (0, &ddgammaold);
And then it's all disguised. There are other things you can do with this piece of code. For example: You can modify this code to make your player hit by something, the screen flashes red, and when you swim to the toxic waste zone, it turns green, and when you drown, it turns blue. You can also change the code to form a fade in, and leave it to others to do it.