|
-
Dec 5th, 2004, 08:36 PM
#1
Thread Starter
PowerPoster
C++: 2D Alpha Blend Q:
Alright I wrote a very basic AlphaBlending technique using Dx7 Surfaces and some Win32API: GetPixel/SetPixel.
Check it out:
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);
}
All I did was get that formula for calculating the finalpixel value...from one of ElectroMans posts on the subject.
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.
Last edited by Electroman; Dec 8th, 2004 at 07:53 PM.
Reason: Added Language to title.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Dec 5th, 2004, 08:45 PM
#2
Re: 2D Alpha Blend Q:
If you want it faster why not use D3D. And use TnL vertices to create your light halos?
-
Dec 5th, 2004, 09:03 PM
#3
Thread Starter
PowerPoster
Re: 2D Alpha Blend Q:
light halo's???
I was pondering using D3D...but it is so much easier to simply modify a surface to have it slowly fade to black.
It is also intensly slow.
I plan on using D3D Alpha for everything else of course...But fading in or out the screen seems easiest with 2D...
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Dec 5th, 2004, 09:07 PM
#4
Re: 2D Alpha Blend Q:
Pretty easy to do fading in D3D too (with alpha blending), here is even an example.
http://www.gametutorials.com/Tutoria...irectX_Pg2.htm
-
Dec 5th, 2004, 09:19 PM
#5
Re: 2D Alpha Blend Q:
He's using DirectX7 and those are DirectX9 examples in www.gametutorials.com . I'm not sure how difficult it would be to convert them.
-
Dec 5th, 2004, 09:22 PM
#6
Re: 2D Alpha Blend Q:
Ohhhhh... ....well that might be a problem...wouldn't be to difficult if he used DX8 tho'...but D3D has big changes between DX7 and DX8..
-
Dec 5th, 2004, 09:23 PM
#7
Re: 2D Alpha Blend Q:
Ohhh...but TnL vertices was in DX7 too... ...so that technique can still be applied...and the best thing is that the coordinates for TnL is in screen coordinates, so that makes them perfect for 2D apps...
-
Dec 6th, 2004, 03:58 PM
#8
Frenzied Member
Re: 2D Alpha Blend Q:
Is this the untitled thread?
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Dec 6th, 2004, 04:13 PM
#9
Re: 2D Alpha Blend Q:
 Originally Posted by Tec-Nico
Is this the untitled thread?
No...the Culling one is...but it got back it's title after I PIIIIIPed the forum...
ØØ
-
Dec 6th, 2004, 09:33 PM
#10
Thread Starter
PowerPoster
Re: 2D Alpha Blend Q:
The allusive untitled thread.
So where did this thread go???
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Dec 7th, 2004, 07:17 AM
#11
Ex-Super Mod'rater
Re: 2D Alpha Blend Q:
 Originally Posted by Halsafar
The allusive untitled thread.
So where did this thread go???
It was to do with the tooltips that give a preview of the thread. For some reason the begining of your thread interferred with the HTML Coments used for the Tooltip and ended up commenting out most of the page . FF only as well.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|