Archived

This topic is now archived and is closed to further replies.

fade in problems

This topic is 5586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi , I am using DDraw Gamma Control to fade out then fade in. Well the fade out works, but when I fade in, it doesn't fade in to the orignal gamma values I stored when I created the gamma control (it comes pretty close, but not perfect). I don't want to have to manually set the orignal gamma values, I want the fade in to go exactly to the orignal gamma values. Any help is well-appreciated!
    

void CDirectDrawGammaControl::FadeIn( void )
{
	int			n, i;
	DDGAMMARAMP originalRamp, currentRamp;
	DWORD time = 0;

	DWORD timeOfLastUpdate = 0;
	int numUpdates = 0;
	int nTargetUpdates = 5;

	originalRamp = m_originalGammaValues;

	bool done = false;

	while ( !done )
	{
		// get the current time

		time = CGameTime::Elapsed();

		if ( time - timeOfLastUpdate > 10 )
		{
			// Get the current gamma ramp.

			_i->GetGammaRamp( 0, ¤tRamp );

			for ( n = 0; n < nTargetUpdates; n++ )
			{
				for (i=0 ; i<256 ; ++i)
				{
					if (currentRamp.red[i] <= originalRamp.red[ i ])
						currentRamp.red[i] -= originalRamp.red[ i ];
					else
						currentRamp.red[i] = 65535;
				}

				for (i=0 ; i<256 ; ++i)
				{
					if (currentRamp.green[i] <= originalRamp.green[ i ])
						currentRamp.green[i] -= originalRamp.green[ i ];
					else
						currentRamp.green[i] = 65535;
				}

				for (i=0 ; i<256 ; ++i)
				{
					if (currentRamp.blue[i] <= originalRamp.blue[ i ])
						currentRamp.blue[i] -= originalRamp.blue[ i ];
					else
						currentRamp.blue[i] = 65535;
				}
			}

			// Set the gamma ramp.

			_i->SetGammaRamp( 0, ¤tRamp );


			// update number of updates done

			numUpdates += nTargetUpdates;

			// set time of last update

			timeOfLastUpdate = time;
		}

		// check if we're done with the fade in

		if ( numUpdates >= 255 - nTargetUpdates )
		{
			done = true;
		}
	}
}

void CDirectDrawGammaControl::FadeOut( void )
{
	int			n, i;
	DDGAMMARAMP	ramp;
	DWORD time = 0;

	DWORD timeOfLastUpdate = 0;
	int numUpdates = 0;
	int nTargetUpdates = 5;

	bool done = false;

	while ( !done )
	{
		// get the current time

		time = CGameTime::Elapsed();

		if ( time - timeOfLastUpdate > 10 )
		{
			// Get the current gamma ramp.

			_i->GetGammaRamp( 0, &ramp );

			// Loop 1 time, dimming each color component by 256 each time.

			for (n=0 ; n<nTargetUpdates ; ++n)
			{
				for (i=0 ; i<256 ; ++i)
				{
					if (ramp.red[i] >= 256)
						ramp.red[i] -= 256;
					else
						ramp.red[i] = 0;
				}

				for (i=0 ; i<256 ; ++i)
				{
					if (ramp.green[i] >= 256)
						ramp.green[i] -= 256;
					else
						ramp.green[i] = 0;
				}

				for (i=0 ; i<256 ; ++i)
				{
					if (ramp.blue[i] >= 256)
						ramp.blue[i] -= 256;
					else
						ramp.blue[i] = 0;
				}

				// Set the gamma ramp.

				_i->SetGammaRamp( 0, &ramp );
			}

			// update number of updates done

			numUpdates += nTargetUpdates;

			// set time of last update

			timeOfLastUpdate = time;
		}

		// check if we're done with the fade out

		if ( numUpdates >= 255 - nTargetUpdates )
		{
			done = true;
		}
	}
}
    
[edited by - randomDecay on August 31, 2002 7:01:20 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Can''t you save gamma values in a variable before you fade out and then fade in to those values rather than using time which can very too much for the accuracy you need.

Share this post


Link to post
Share on other sites