Advertisement

Fade

Started by March 11, 2000 05:48 AM
3 comments, last by Xeno 24 years, 9 months ago
How do i Fade pictures into some color in Directx?

------------------------------- Goblineye Entertainment------------------------------

If your graphics card supports it then you can use IDirectDrawColorControl, otherwise you will have to lock your surface and manually change the pixels. Another alternative would be to use Direct3D.

Hope this helps.

--Antz
Quanta
http://quanta.virtualave.net
Advertisement
lets say i want to fade the picture to black and i do it manually, and lets say i got some pixel so what i need to do is that - (R-1,G-1,B-1)? until the pixel turns to black?

------------------------------- Goblineye Entertainment------------------------------

You can do it that way, but say you had the colour RGB=(200,50,0) if you -1 off each component your green component would run out more quickly.
A better method would be to fade a percentage of each component colour at each iteration through the fade step.
This would allow a smoother fade. Say take off 10% each iteration, that way each RGB value decreases in a uniform amount relative to its value.

I've haven't done this in a long time, so someone scream at me if I'm crazy.

Edited by - Darrell on 3/11/00 8:53:14 AM
I also agree that subtracting 1 off each RGB component is not the best
way to do it, since sometimes your picture turns into ugly blotches
(it is not an uniform fade).

The D3D IM way (DirectX 7.0):

Let''s say you want to fade out the entire screen to black. Create a
rectangle polygon (two triangles). You will use this to cover your
entire screen.

Then create a solid black colored material for this polygon and set
its diffuse alpha component to zero:

D3DMATERIAL7 material;
D3DUtil_InitMaterial(material, 0.0f, 0.0f, 0.0f); // black
material.diffuse.a = 0.0f; // (0% alpha)


An alpha value of 0.0 means everthing will show through your polygon,
and an alpha value of 1.0 means nothing will show through, so it
will be solid black (e.g. the color of the material that you created
it with).

When you begin to render your scene, enable alpha blending and setup
your render states for translucency:

// enable alpha blending
lpdevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE );

// source, dest
lpdevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA );
lpdevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA );


Set the material to the device, draw your polygon, then gradually increase
your material''s diffuse alpha component from 0.0f to 1.0f after each time
you render your scene.

I know I''ve left a lot of basic stuff out, but if you are already
familiar with D3D IM, then it should be a piece of cake to get it
working in a couple of minutes.

Rasta

This topic is closed to new replies.

Advertisement