Alright I wrote a very basic AlphaBlending technique using Dx7 Surfaces and some Win32API: GetPixel/SetPixel.
Check it out:
All I did was get that formula for calculating the finalpixel value...from one of ElectroMans posts on the subject.PHP Code://-----------------
//Alpha Blend -- DC Basic
//-----------------
void DDSurface7::AlphaBlendDC(LPDIRECTDRAWSURFACE7 &Destination, USINT AlphaValue)
{
COLORREF SrcRGB, DestRGB;
BYTE r,g,b;
HDC hdcDestination=0, hdcAlpha=0;
while (AlphaValue > 255) AlphaValue -= 255;
Destination->GetDC(&hdcDestination);
m_AlphaSurface->GetDC(&hdcAlpha);
for (USINT y = 0; y < m_Height; y++)
{
for (USINT x = 0; x < m_Width; x++)
{
SrcRGB = GetDCPixel(x,y);
DestRGB = GetPixel(hdcDestination, x,y);
r = (AlphaValue * ( GetRValue(SrcRGB) + 256 - GetRValue(DestRGB) )) / 256 + GetRValue(DestRGB) - AlphaValue;
g = (AlphaValue * ( GetGValue(SrcRGB) + 256 - GetGValue(DestRGB) )) / 256 + GetGValue(DestRGB) - AlphaValue;
b = (AlphaValue * ( GetBValue(SrcRGB) + 256 - GetBValue(DestRGB) )) / 256 + GetBValue(DestRGB) - AlphaValue;
SetPixel( hdcAlpha,x,y,RGB(r,g,b) );
}
}
Destination->ReleaseDC(hdcDestination);
m_AlphaSurface->ReleaseDC(hdcAlpha);
}
Now what this does essentially is:
Loops through row by row.
Gets the pixel from the surface in the class and the destination surface passed.
Calculates the proper alpha value.
Sets the pixel in a new surface which is then bltfast to the screen later.
My problem is:
I know 2D Alpha is naturally slow, but jeez, doing it every frame takes at least 10 seconds a frame on my comp for a picture the size of the screen.
This is super slow...
It works...works fine. I get a nice alpha blend for translucency.
All I really need it for is screen fading...Nothing more.
