Archived

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

Fading Effects

This topic is 5700 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! 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!!!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!!!

Share this post


Link to post
Share on other sites
HI!

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

Firlefanz

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!!!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites