Hey,
Could someone explain to me how to do a fade out/in using the gamma control with DX8?
Thanks ahead of time.
Hey,
Could someone explain to me how to do a fade out/in using the gamma control with DX8?
Thanks ahead of time.
here's some code:
// Globals
LPDIRECTDRAW lpdd = NULL;
LPDIRECTDRAWSURFACE lpddsPrimary = NULL;
LPDIRECTDRAWGAMMACONTROL lpddgc = NULL;
bool GammaOK = false;
// Initialises gamma ramping control. Must be called for fading to work. Stores pointer
// to gamma control in lpddgc, and set GammaOK to true if successful.
bool InitGammaRamp(void)
{
// Get driver capabilities to determine gamma support.
DDCAPS ddcaps;
ZeroMemory(&ddcaps, sizeof(ddcaps));
ddcaps.dwSize = sizeof(ddcaps);
lpdd->GetCaps(&ddcaps, NULL);
// Does the driver support gamma?
if(!ddcaps.dwCaps2 && DDCAPS2_PRIMARYGAMMA)
{
return FALSE;
}
// Get the actual gamma control object
if(lpddsPrimary->QueryInterface(IID_IDirectDrawGammaControl,(LPVOI D*)&lpddgc) != DD_OK)
{
return FALSE;
}
GammaOK = TRUE;
return TRUE;
}
// This will set the screen brightness to a percentage of total brightness
// (eg. 0 = black, 100 = normal). It doesn't perform a full fade on it's own,
// that's up to your program (eg. increment fade variable, call FadeBlack, repeat till 100%)
// This is so it doesn't tie up control of your program, and so you can still move objects
// while fading.
void FadeBlack(int Percent)
{
// Check gamma control is initialised
if (!GammaOK)
{
return;
}
// Convert 0-100 Percentage to 0-255 Byte
int NewPercent = (int)((float)Percent * 2.55);
DDGAMMARAMP ddgr;
WORD dwGamma;
ZeroMemory(&ddgr, sizeof(ddgr));
if (lpddgc->GetGammaRamp(0, &ddgr) != DD_OK)
{
return;
}
dwGamma = 0;
for(int iColor = 0; iColor < 256; iColor++)
{
ddgr.red[iColor] = dwGamma;
ddgr.green[iColor] = dwGamma;
ddgr.blue[iColor] = dwGamma;
dwGamma+=(WORD)NewPercent;
}
lpddgc->SetGammaRamp(0, &ddgr);
}
also, if you downloaded the dx8vcsdk.exe (~50MB) from microsoft, check the samples, there's an example there somewhere in the DirectDraw section.