alpha blending code

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
somename
Posts: 9
Joined: March 13th, 2013, 6:34 am

alpha blending code

Post by somename » April 3rd, 2013, 12:23 pm

i was trying to add png files to my game, but it didn't work.
i literaly copied everything related (apearently i forgot something) from chili I6 lesson downloads
and the funny thing is: the same picture with same functions works on the download, but not in my game.
any help?

http://www.speedyshare.com/Rb5qU/alphabug.rar

Yeti4000
Posts: 6
Joined: April 2nd, 2013, 6:09 pm

Re: alpha blending code

Post by Yeti4000 » April 5th, 2013, 1:31 pm

i have the exact same problem oO

in ''my'' version ( i took the Font project chili uploaded and only edited the alpha parts along to chilis insturctions) it just wont work..

but the download version for lesson I6 perfectly works...

i cant find any mistake i have made ...(which doesnt mean alot i guess :D ...propably ive done sth stupid and just dont get it, programming is quite new to me)


by debugging i figured out that "my" version fails to load the png file...
the width and height is set to 0
(i browesd through Gdiplus.h and Bitmap.h and as far as i can tell 0 is the default setting)
surface isnt set up either...

but i couldnt fix it :S

pls help^^ i just NEED to know it ;P things like that bother me... i just hate not to get why it fails :S
Attachments
alphafail.zip
(1 MiB) Downloaded 131 times

Conflictus
Posts: 53
Joined: January 7th, 2013, 8:09 am

Re: alpha blending code

Post by Conflictus » April 5th, 2013, 8:20 pm

@Yeti4000

Inside D3DGraphics.cpp

const D3DCOLOR dst = GetPixel( x, y );

Missing the offset values for x and y for GetPixel()

const D3DCOLOR dst = GetPixel( x + xoff, y + yoff);

//extract channels
const unsigned char dstAlpha = (dst & 0xFF000000) >> 24;

This line can be removed. There is no dstAlpha.

//blend channels
const unsigned char rltRed = (srcRed * srcAlpha + dstRed * ( 255 - dstAlpha ) ) / 255;
const unsigned char rltGreen = (srcGreen * srcGreen + dstGreen * ( 255 - dstGreen ) ) / 255;
const unsigned char rltBlue = (srcBlue * srcBlue + dstBlue * ( 255 - dstBlue ) ) / 255;

The above for blending channels should look like this:

const unsigned char rltRed = (srcRed * srcAlpha + dstRed * ( 255 - srcAlpha ) ) / 255;
const unsigned char rltGreen = (srcGreen * srcAlpha + dstGreen * ( 255 - srcAlpha ) ) / 255;
const unsigned char rltBlue = (srcBlue * srcAlpha + dstBlue * ( 255 - srcAlpha ) ) / 255;


There may be more that needs fixing.

Yeti4000
Posts: 6
Joined: April 2nd, 2013, 6:09 pm

Re: alpha blending code

Post by Yeti4000 » April 6th, 2013, 10:20 am

ty conflictus

i found the missing xoff,yoff last night myself but missed the
mistakes in blending so ty for that
(i think i suck at proofreading my own code because i pretty much read what i expect to read and not whats really there... )

drawing with alpha works now.. tried it with some hardcodings


however i still cant figure out why the png loading fails

somename
Posts: 9
Joined: March 13th, 2013, 6:34 am

Re: alpha blending code

Post by somename » April 6th, 2013, 12:43 pm

well... somehow that's not helping me, since that's what is written in my version,
also, i load the sprite perfectly, i just can draw it..

Conflictus
Posts: 53
Joined: January 7th, 2013, 8:09 am

Re: alpha blending code

Post by Conflictus » April 6th, 2013, 4:23 pm

@yeti4000

There's a typo in LoadSpriteAlpha() inside D3DGraphics.cpp

change it to Gdiplus::Bitmap bitmap( L"alphahalf.png" );

@somename

//Game.cpp
LoadBMP( chr[0], "maple\\dude1.bmp" );
LoadBMP( chr[1], "maple\\dude2.bmp" );
LoadBMP( chr[2], "maple\\walking.bmp" );
LoadBMP( enemy,"maple\\enemy.bmp");
LoadBMP( Skill,"maple\\SKILL.bmp");
LoadBMP( Jump,"maple\\jump.bmp");
LoadBMP( Jumpstate,"maple\\jumpstate.bmp");
LoadBMP( Airmob[0], "maple\\airmobBEST0.bmp");
LoadBMP( Airmob[1], "maple\\airmobBEST1.bmp");
LoadBMP (skillwindow, "maple\\skillwindow.bmp");
LoadBMP (portal, "maple\\portal.bmp");
LoadBMP (airskillicon, "maple\\airmobskillicon.bmp");
LoadBMP (Bluefireball,"maple\\bluefireball.bmp");
LoadBMP (spin[0],"maple\\spin0.bmp");
LoadBMP (spin[1],"maple\\spin1.bmp");
LoadBMP (spin[2],"maple\\spin2.bmp");
LoadBMP (spin[3],"maple\\spin3.bmp");
LoadBMP (spin[4],"maple\\spin4.bmp");
LoadBMP (spin[5],"maple\\spin5.bmp");
LoadBMP (skillbutton, "maple\\skillbutton.bmp");
LoadBMP (waterskill[0],"maple\\waterbending01.bmp");
LoadBMP (waterskill[1],"maple\\waterbending02.bmp");
LoadBMP (waterskill[2],"maple\\waterbending03.bmp");
LoadBMP (waterskill[3],"maple\\waterbending04.bmp");
LoadBMP (skillmenu,"maple\\menupanel.bmp");
LoadBMP (arial9,"maple\\arial9.bmp");
LoadBMP (azula,"maple\\azulasprites.bmp");
LoadBMP (bars,"maple\\hpmpexpbars.bmp");
LoadBMP (levelfont,"maple\\levelfont.bmp");
LoadBMP (weapon,"maple\\weapon.bmp");

//D3DGraphics.cpp
Gdiplus::Bitmap bitmap( L"maple\\airattak.png" );

There is no maple directory and aside from airattak.png most of these aren't included with the project.

somename
Posts: 9
Joined: March 13th, 2013, 6:34 am

Re: alpha blending code

Post by somename » April 7th, 2013, 4:19 pm

then erase it... didn't want to give my sprites out :(
i am only having the problem with the png.. all the program without it works fine

Yeti4000
Posts: 6
Joined: April 2nd, 2013, 6:09 pm

Re: alpha blending code

Post by Yeti4000 » April 7th, 2013, 5:35 pm

well.. ty conflictus :D

i knew i was just beeing retarded ;P just couldnt find the right spot^^

i actually checked that line, because its one of the more obvious places to fuckt the loading funktion up.. but however i just read what i wanted to read :S

Post Reply