Okay, here are my two fade functions. The first, Fade2Black(), works perfectly. The second, FadeFromBlack(), does not. They are identical in every way, except for what they do with the alpha channel.
So what is the problem exactly? FadeFromBlack(), after bringing up the alpha channel to make the fullscreen black quad, BlackBox, transparent, sort of starts over. I can make it stop if I do not reset the values before I return 1 and exit, but then it won't run twice as those values must be reset before it runs again.
I've been working on this stupid fade for days and days, and I'm really getting ANGRY. If anyone has an idea why FadeFromBlack() isn't working, or simply has a better fade function, please oh please won't you help a poor boy not go insane?
FADE2BLACK():
//Fades screen to black. Pass "fast" or "slow".
bool Fade2Black(char* speed)
{
//First draw a transparent black quad on the screen
BlackBox.Draw(blackBoxBuffer,NULL);
static DWORD currentColor = 0x00000000; //Transparent Black
//Assign the quad's vertex colors
BlackBoxVertices[0].color = currentColor;
BlackBoxVertices[1].color = currentColor;
BlackBoxVertices[2].color = currentColor;
BlackBoxVertices[3].color = currentColor;
//Grab the first byte of the color, which is the alpha value
static DWORD dwAlpha = (currentColor>>24)&0x00;
//Increment the alpha value if it isn't fully opaque
while (dwAlpha != 0xFF)
{
if (speed == "fast")
{
dwAlpha += 0x11;
}
else if (speed == "slow")
{
dwAlpha += 0x01;
}
else
{
//error
}
//Store the alpha value back into the color
currentColor = (currentColor&0x00000000)|(dwAlpha<<24);
//This is the D3D equivalent to DDraw's flip surface command
hr=blackBoxBuffer->Lock(0,0, &vb_vertices,0);
memcpy(vb_vertices, BlackBoxVertices, sizeof(T_VERTEX)*4 );
blackBoxBuffer->Unlock();
return 0;
}
//If we are where we should be
if (currentColor == 0xFF000000)
{
//Reset the color and return
currentColor = 0x00000000;
dwAlpha = 0x00;
return 1;
}
else
return 0;
}//end Fade2Black()
FADEFROMBLACK():
//Fades screen from black. Pass "fast" or "slow".
bool FadeFromBlack(char* speed)
{
//First draw a transparent black quad on the screen
BlackBox.Draw(blackBoxBuffer,NULL);
static DWORD currentColor = 0xFF000000; //Opaque Black
//Grab the first byte of the color, which is the alpha value
static DWORD dwAlpha = (currentColor>>24)&0xFF;
//Assign the quad's vertex colors
BlackBoxVertices[0].color = currentColor;
BlackBoxVertices[1].color = currentColor;
BlackBoxVertices[2].color = currentColor;
BlackBoxVertices[3].color = currentColor;
//Increment the alpha value if it isn't fully opaque
while (dwAlpha != 0x00)
{
if (speed == "fast")
{
dwAlpha -= 0x11;
}
else if (speed == "slow")
{
dwAlpha -= 0x01;
}
else
{
//error
}
//Store the alpha value back into the color
currentColor = (currentColor&0x00000000)|(dwAlpha<<24);
//This is the D3D equivalent to DDraw's flip surface command
hr=blackBoxBuffer->Lock(0,0, &vb_vertices,0);
memcpy(vb_vertices, BlackBoxVertices, sizeof(T_VERTEX)*4 );
blackBoxBuffer->Unlock();
return 0;
}
//If we are where we should be
if (currentColor == 0x00000000)
{
//Reset the color and return
//This is causing a problem here
currentColor = 0xFF000000;
dwAlpha = 0xFF;
return 1;
}
else
return 0;
}//end FadeFromBlack()
Edited by - The Pale Hunter on February 19, 2002 9:06:55 PM
Edited by - The Pale Hunter on February 19, 2002 9:08:08 PM