Advertisement

DDraw Fade function in 16 bit color ??

Started by March 07, 2000 12:12 PM
9 comments, last by Helius 25 years ago
Does anyone knows how can I implement a fade in/out function with Direct Draw in 16 bit color?
You would have to do it yourself by locking the surface and then fading each pixel.
Advertisement
If you have an alpha blending routine, you could take a surface that''s the size of your display surface and blend the two together.

If you don''t have an alpha blending routine, check out the MMX alpha blending article in the programming section here at GameDev.Net. You could also do some research and use Direct3D to implement 3D hardware accelerated alpha blending.

Josh
http://www.jh-software.com
Joshhttp://www.jh-software.com
Another (much faster) way is to use the Gamma Control to fade out the screen. I don''t know if all monitors support this, though...

/ LC
-------------------------------------------------------------LGPL 3D engine - http://www.sourceforge.net/projects/realityengine
Not all video cards allow for gamma fading. There fore it's not the best alternative to fading pixel by pixel. The routine is fairly simple.

While (all pixels aren't black)
{
destination pixel red value = source pixel red value /2;
destination pixel green value = source pixel green value /2;
destination pixel blue value = source pixel blue value /2;
}

(note this is just a deriavation of a software alpha blending routine. Because the goal is to fade to black (RGB 0,0,0) we can change the formula from destination pixel = source pixel+alpha pixel/2 to destination pixel=source pixel/2 because the alpha pixel is 0!)

Edited by - evaclear on 3/7/00 10:32:59 PM
Joseph FernaldSoftware EngineerRed Storm Entertainment.------------------------The opinions expressed are that of the person postingand not that of Red Storm Entertainment.
Thank you all !!!

Nacho.
Advertisement
Go there, a great tutorial on how to fade 16bit surface.
You can fade to black, fade to surface and Alpha Transition between to surfaces.

http://www4.netease.com/~codingboy/gpfan/stunt/ddfade.html
If you really wanna do it fast, you can use D3D to set the material color and fade it that way...but that would be a little too much work. This would work on all computers, as long as you''ve got DirectX installed.

You can detect gamma support with IDirectDraw7::GetCaps.

============================
Daniel Netz, Sentinel Design

"I'm not stupid, I'm from Sweden" - Unknown
============================Daniel Netz, Sentinel Design"I'm not stupid, I'm from Sweden" - Unknown
For fast software alpha-blending I am using some kind of look-up table with precomputed values for every possible color and every alpha value. Something like this:

// alpha map for 32 alpha shades
WORD AlphaMap[32][65536];

It takes 4MB of RAM! But it is very fast, so who cares.

Hey - that''s a good idea!

I think the fades in "Age of Empires 2" are done that way. They were too fast to be real-time calculations on my old Pentium 166.

And what''s 4 Megs today ?!

This topic is closed to new replies.

Advertisement