Fading Effects

Started by
7 comments, last by FooFighter 21 years, 10 months ago
Hi! When changing screens in games, its nice to have a cool fading effect to make it smoother, but I don''t have any idea how could I do this! I would like to know how could I do pallete fading effects with DelphiX...if anyone know that, please, tell me thanks in advance , Marcelo. Delphi just rules!!!
Delphi just rules!!!
Advertisement
There are details of how to do palette animation (fade in fade out and flash) using DelphiX in the DelphiX help file, and there is a demo program to demonstrate. Note that palette animation can only be done when you are using 256 or less colours.

If you want to do a fade when in 16/24/32 bit colour, you will either need to use alpha blending, or you can use the GammaRamp (though this is not supported on many older graphics cards). For how to do alpha blending have a look at this article, or for gamma ramps look at this one. Both of those give their examples in C++, but it shoufdn''t be too hard to understand. I believe Joffa (a game made with DelphiX) used gamma ramps to perform fades, so you could look at it''s source if your''e stuck.

BTW: like the sig
[ PGD - The Home of Pascal Game Development! ] [ Help GameDev.net fight cancer ]
Hello!

Thank you for the asnwer!

I choosed the Gamma Control becouse it looked easyer to program than Alpha Blending.

The tutorial is good, but as it is for C++ and the DirectX SDK, it becomes harder to programming the fading effects in my DelphiX game.

I think I converted all the code correctly but one line in the tutorial I ripped out becouse I think DelphiX has this already implemented (the QueryInerface line below). So the code:

//-----------------------------------------------------------------------------------------------------------------//

procedure Fade;
var
DDGammaRamp : TDDGammaRamp;
DDGammaOld : TDDGammaRamp;
backloop : integer;
begin

//The code lpddsprimary->QueryInterface(IID_DirectDrawGamaControl,(void**) &lpDDGammaControl) I could not convert.

//Form1.DXDRaw1.Surface.GetInterface(IID_IDirectDrawGammaControl); //I tryed but...couldn''t

FOrm1.DXDraw1.Surface.GammaCOntrol._AddRef(); //I think this starts the GammaControl or something like that




Form1.DXDraw1.Surface.GammaControl.GetGammaRamp(0,DDGammaOld);
Form1.DXDraw1.Surface.GammaControl.GetGammaRamp(0,DDGammaRamp);
//

for backloop := 0 to 256 do
begin
if DDGammaRamp.Red[backloop] > 0 then
begin
DDGammaRamp.Red[backloop] := 0;
Form1.DXDraw1.Surface.GammaControl.SetGammaRamp(0,DDGammaRamp);
end;
Sleep(1);

if DDGammaRamp.Green[backloop] > 0 then
begin
DDGammaRamp.Green[backloop] := 0;
Form1.DXDraw1.Surface.GammaControl.SetGammaRamp(DDSGR_CALIBRATE,DDGammaRamp);
end;
Sleep(1);

if DDGammaRamp.Blue[backloop] > 0 then
begin
DDGammaRamp.Blue[backloop] := 0;
Form1.DXDraw1.Surface.GammaControl.SetGammaRamp(DDSGR_CALIBRATE,DDGammaRamp);
end;
Sleep(1);
end;

Form1.DXDraw1.Surface.GammaControl.SetGammaRamp(0,DDGammaOld);
FOrm1.DXDraw1.Surface.GammaCOntrol._Release;
end;

//----------------------------------------------------------------------------------------//

Ok, So to test this procedure, I did a "If Ord(Key) = 70 then Fade; in my Form1.OnKeyDown.

The problem is: When I press "F" (CODE = 70) the surface does not fades and the game just pauses
for 3 secs.

What am I doing wrong?

Thanks in advance,

Marcelo.

Delphi just rules!!!
Delphi just rules!!!
Be warned that gamma control probably isn''t implemented on all hardware.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
HI!

Is there a possibility to find out which graphic card does support gamma control?

Firlefanz
Visit my homepage www.ericbehme.deDon't miss the download section ;)
You can check the caps for your primary surface using the function IDIRECTDRAWSURFACE7.GetCaps(). Here''s a snippet:
var  caps: TDDSCaps2;begin  FlpddsPrimary.GetCaps(caps);  if caps.dwCaps2 and DDCAPS2_PRIMARYGAMMA <> 0 then  begin    // we have hardware support  end; 

That''s for your plain old DirectDraw - not for DelphiX. I''m sure that DelphiX provides some property for this, so you''ll have to play around.

Two notes:
1) I''ve never used the above code in practise, so it may not be right...
2) There''s more info (in C++, natch) over at MSDN
Thank you everyone for the replys.

I would be nice if anyone who owns Delphi and DelphiX could teste the code above, the report me if you get a fade or not.

Thanks,

Marcelo.

Delphi just rules!!!
Delphi just rules!!!
why not just use an alpha blended quad? i know its the simple answer that works on all hardware, and very obvious still it may just work.
Yeah, one easy way to use alpha blending to perform a fade in DelphiX is to use the TDirectDrawSurface.FillRectAlpha method. I can''t remember the exact syntax, but one parameter is a rectangle (use the SurfaceRect), a color (use clBlack) and the alpha value (0..255). Just set up a for loop to cycle from transparent to opaque.
[ PGD - The Home of Pascal Game Development! ] [ Help GameDev.net fight cancer ]

This topic is closed to new replies.

Advertisement