Fast Software Alpha Blending In 2D
Question submitted by (25 June 1999)




Return to The Archives
 
  I am using DirectDraw for my newest 2D project. I have done a lot of research on alpha blending effects and got out a lot from the web. Currently, they are as follows (for implementing fast alpha blending):
  • Using a 3D Accelerator and D3D -- relevant w/ DDraw
  • Using a 3D Accelerator and OpenGL -- not relevant w/ DDraw
  • Using a 3Dfx card and Glide -- not relevant w/ DDraw


  • I have worked on the above, and found out that it was the way to go (using a 3D accelerator). *However* I also found out that they dont work/work really slowly with the systems that dont have a 3D Accelerator. And my goal is to provide descent fps on systems w/o a 3D Accelerator. So, I turned to software methods. I have found out the basic algorithm and it works good -- only thing is, its really slow (I get 5 FPS to blend 320x240 pixels w/ another 320x240 pixels image!). I have considered using look-up-tables. However, they are irrelevant in 24 and 32 BPP modes (which I plan on supporting... :-)). I mean a LUT in 24 BPP would be 2^24 DWORDs! And in 32 BPP, it would be 2^32 DWORDs.

    So, my question is, how is it possible to do *software* alpha blending getting descent fps (above 24), on even an "old" system :-) I've read the article on GameDev.net on MMX optimized alpha blending, however, I am one w/o MMX processor. I know that alpha blending in software has got to do something w/ ASM. Alas! Only if I knew how! :-)
     
     

     
      Personally, my way of dealing with this was to find someone else who had already done the assembly work (optimizing alpha blending for me), so I'm using DigitalFX ( www.fastprojects.com ) as a blitting library. There are other sources out there that do similar things as well. You can take the packaged API road like this or do it yourself by spending time learning about different techniques which are better left to technical articles on assembly optimization already available on the net. Really, there isnt a quick fix to this beyond hardware solutions, it is just a problem of having to do a lot of calculations as fast as possible.

    It's also important to keep in mind that slower machines are just not going to be capable of processing a lot of information while drawing to the screen and performing alpha blending, depending on the screen size and bit depth. You are probably being unrealistic in hoping to do 24 and 32 BPP alpha blending on older machines, even in 640x480 mode, without hardware acceleration. However, some amount of blending is possible in 640x480 16bpp mode on pre-MMX systems, and its really a matter of tweaking what you want your outcome to look like to use whatever resources you have to make this possible.



    Response provided by Geoff Howland
     
     

    This article was originally an entry in flipCode's Fountain of Knowledge, an open Question and Answer column that no longer exists.


     

    Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
    Please read our Terms, Conditions, and Privacy information.