Skip to main content
gamedev.net
🔒 Locked

Fading

Started by Deadman55 2 replies 200+ views
Original Post
Deadman55
Deadman55
Can somebody help me out here? I''m trying to perform a fade to black using a 2D quad rendered all over the screen and then I suppose you''d do some blending operations or simply alter the quad''s alpha somehow.. I don''t know where to start. All I''ve done so far is rendered the quad (all is black).
Crazy_Vasey
Crazy_Vasey
I don''t know Direct3D very well right now (more of an OpenGL guy at the mo) but I''ll describe a method that I think should work.

This assumes that an alpha of 1.0 is complete transparency and 0.0 is no transparancy at all , that''s how it works in OpenGL and SDL (well it''s 0 to 255 in SDL but nevermind).

The first thing you need to work out is the decrement value. This is dependant on how many frames you want to spend on the fade, you calculate it as 1.0 / number of frames in fade. Pretty easy to do yeah? Right with that done you''re ready to start on the fade.

First off you start with the alpha at 1.0. You render your scene as normal then blat a quad over the top of it with 1.0 alpha, then you loop for the number of frams you spend on the fade and render it with progressively less alpha (using the previously calculated decrement value) and that should give you a fade to whatever colour you use for the quad. I think.

I''d give you some code but I don''t know Direct3D at all right now, I''m just downloading the DX9 SDK to get started on it. I''ll give you some pseudo code, it might help after all.

function Fade(int numOfFrames)
begin
float decrement = 1.0 / numOfFrames
float currentAlpha
loop from 0 to numOfFrames
begin
let currentAlpha = currentAlpha - (loopCounter * decrement)
RenderScene
Render Quad to blend with using currentAlpha
end loop
end function

I hope that helped
Deadman55
Deadman55
Thanks. U the man!
gommo
gommo
I was having problems with that exact thing myself, as most images I had I didnt want to have to programmatically change the alpha channel each frame.

If you use ID3DXSprite you can load a texture in, scale it to the screen and also override the alpha channel each time you call Draw(). That way you just call draw() progressivly altering the alpha channel and there you have it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.