2D Alpha Blending Using MMX Technology
Get the source code for this article here IntroductionMany things have changed since the day I got my first computer. While it used to be common practice to squeeze all you could out of your machine, it is now customary to rely on 3D accelerators and blame the hardware for poor performance. It is not surprising that websites dealing with alpha blending usually suggest giving up software implementations and making use of hardware support. However, there are coders who do not have sophisticated hardware or who simply want to keep the system requirements for their game within a reasonable range. These people are having a hard time trying to get information from the Internet, so I felt that something had to be done. I also believe that making source code available for other programmers can be beneficial for both the originator and those who study his code, as one of them might find a way to improve it. Besides, in most cases the author is dependent on the help of others as well, and as this was the case with me, I thought it was time to give something back. DescriptionThis is the point where I want to give credit to John Hebert. He is the author of the only useful article on alpha blending I found, and some of his ideas have made their way into my implementation. If you want to know all the theory about alpha blending, please refer to his article. However, I think I was able to make some improvements on his version. Here is a brief overview of what has changed:
According to my experience as a games programmer, there are only two types of alpha blending you need: one that uses arbitrary alpha values (e.g. in order to fade in your logo in the intro) and one that uses a fixed alpha value (e.g. to make an explosion or a cloud appear translucent). I implemented both an MMX and a standard version for each type, consequently the core of my library consists of four functions: BltAlpha() - Blits a DirectDraw surface onto another one, using a variable value for alpha. BltAlphaMMX() - Same as BltAlpha(), but uses MMX. BltAlphaFast() - Blits a DirectDraw surface onto another one, using a fixed alpha value of 0.5. BltAlphaFastMMX() - Same as BltAlphaFast(), but uses MMX. Each function can handle 16, 24 and 32 bit, where the 16 bit mode is subdivided into 555, 565 and a generic mode. A function that can detect MMX technology on a processor is also included. The source code is thoroughly commented, and every function is preceded by a description of its usage. The project was created using Microsoft Visual C++ 6.0 and is ready to be compiled and executed. I also included a ReadMe file, which contains license information, file IDs and contact information. ConclusionI do not claim that the code is perfect in any way, but I tried all my best, so take a close look at it and see if you can improve it. I also assume that the alpha blending routines do not contain any bugs, but thatīs what you always think, so please let me know if you find any. The entire source code is freeware, and you may use it in whatever way you like. You are also allowed to use it in any commercial software without having to pay a single buck to me. However, I do not want you to charge money for the source code, as I want to make sure that it remains available for everyone. If you find ways to improve the source code, please drop me a line, as this is one reason why I made this code public. Here's how you can reach me: Email: hofmann@anvil-soft.com Website: www.anvil-soft.com Matthias Hofmann Discuss this article in the forums
See Also: © 1999-2011 Gamedev.net. All rights reserved. Terms of Use Privacy Policy
|