Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

baddrizz

alpha blending in win32 questions

This topic is 5934 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok here''s the story i''m making a simple prog for a friend and i want to have it fade from one screen to the next using alpha blending (or anything else if u guys have any ideas ) i got everything working pretty good it fades in and out but the prob is some of the colors flash in the oddest posible colors. like it is supposed to fade in to blue lets say but in the process it''ll flash from red to a hole bunch of purples so i''m hopping u guys can help me out with this one cause well i can''t figure it out what i''v done is set up 3 different DIB''s so i can draw on them 1.mdc 2.cdc 3.ddc and the main dc hdc then i blit the first pic to mdc and the second pic to cdc perform all the calculations using this code and put the finished pic onto ddc and blit that to the screen....

for(int y = 0; y < 240; y++)
	{
	for(int x = 0; x < 240; x++)
	{
	        DWORD color = pbit1[y*240+x];

		char r = (color & 0x00FF);
		char g = (color & 0x00FF00) >> 8;
		char b = (color & 0x00FF0000) >> 16;

		color = pbit2[y*240+x];

	        char r2 = (color & 0x00FF);
		char g2 = (color & 0x00FF00) >> 8;
		char b2 = (color & 0x00FF0000) >> 16;

		char R = r2 + (( r2 - r) * alpha);
		char G = g2 + (( g2 - g) * alpha);
		char B = b2 + (( b2 - b) * alpha);
			
		pbit3[y*240+x] = RGB(B,G,R);
 	}
}
alpha++; //add the the alpha for a fade in

BitBlt(hdc, 0, 0, 240, 240, ddc, 0, 0, SRCCOPY);

 
if u see anything wrong with this code or know a better way to do the fade don''t be afraid please tell me i''m a newbie so i won''t mind ohh i''m using 32bit and i know the code isn''t optomized in any way yet i just want to get it working thx for any help

Share this post


Link to post
Share on other sites
Advertisement
char R = r2 + (( r2 - r) * alpha);
char G = g2 + (( g2 - g) * alpha);
char B = b2 + (( b2 - b) * alpha);

should be (assuming alpha is 0-255)
uchar R = ((r2*(0xFF-alpha)) + (r*alpha))>>8;
uchar G = ((g2*(0xFF-alpha)) + (g*alpha))>>8;
uchar B = ((b2*(0xFF-alpha)) + (b*alpha))>>8;

and r2, r, g2, etc should all be ints.

that will give you a crossfade with increasing alpha values favoring the pbit1 image instead of the pbit2 image.

Share this post


Link to post
Share on other sites
k well i took ur idea and converted r,g,b,r2,g2,b2 to ints and then used the routine u gave

((r2*(0xFF-alpha)) + (r*alpha))>>8;

and it worked but it took away my color''s so is there a way to get them back?

Share this post


Link to post
Share on other sites
what do you mean it took your colors away? thats the standard alpha blending algo used by all. including 3d cards (though they may get better percision). if you mean how do you reverse the effect, simply decrease or increase (depends on which drection you are going) the alpha value (must be in a range of 0-255 or things get screwed up).

if you mean that when the alpha value is at 0 or 255 the other image is completely gone, thats the point. thats how bledning works. just dont use values that high or low if you dont want things to go that extreme.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!