Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Alpha Channel

This thread is locked; no one can reply to it. rss feed Print
Alpha Channel
Mariusz
Member #1,634
November 2001

Can anyone help me out with alpha channel issue? I have created an image using PS5.5 and made an alpha channel for my selection. As a next step, I have saved this image as a Targa (TGA) format including alpha channel.

My question is how do I load this image back to my Allegro project? I want to display it over other backgrounds so it would create transparency in the areas where it should. I have seen some DirectX demos a while ago where a particle system would be using some alpha channels (it looked really nice.)

I would really appreciate if someone had a link or an example of how to accomplish alpha channel within the Allegro.

Best regards,
Marius

Steve Terry
Member #1,989
March 2002
avatar

bmp = load_bmp("blah.tga", NULL);
set_alpha_channel();
blit(bmp, buffer, 0, 0, 0, 0, bmp->w, bmp->h);

I mean it's not hard ;D

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Oscar Giner
Member #2,207
April 2002
avatar

To load the image you must be sure that it's loaded in a 32bpp bitmap. For that, you have to disable color conversion:

set_color_conversion(COLORCONV_NONE);
image_with_alpha = load_bitmap("file.tga", NULL);
set_color_conversion(COLORCONV_TOTAL);

To blit you just have to enable alpha blending:

drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
set_alpha_blender();
// blit the alpha image
solid_mode();

[edit]

Quote:

set_alpha_channel();

Steve, you just made that up, didn't you? :P

Steve Terry
Member #1,989
March 2002
avatar

>_< I had alpha channel in my mind when I wrote that... it's a typo yes ;D

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Mariusz
Member #1,634
November 2001

Thank you guys so much! This is one of the best places to get some answers :-)

Steve Terry
Member #1,989
March 2002
avatar

You better believe it 8-)

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Mariusz
Member #1,634
November 2001

Worked like a charm ;D

Thomas Fjellstrom
Member #476
June 2000
avatar

WE rule, and GameDev drools ;D

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Gideon Weems
Member #3,925
October 2003

Hahaha. Sorry to interrupt the scheduled victory dance, but what's the point of draw_trans_sprite() if a regular blit does the same thing?

Steve Terry said:

    bmp = load_bmp("blah.tga", NULL);
    set_alpha_channel();
    blit(bmp, buffer, 0, 0, 0, 0, bmp->w, bmp->h);

Oscar Giner
Member #2,207
April 2002
avatar

I wouldn't look much to Steve's code ;):P

Steve Terry
Member #1,989
March 2002
avatar

:'(:'(:'(:'(:'(:'(:'(:'(:'(:'(:'(
I wrote it in a hurry and wasn't thinking
/me goes back to RTFM :P

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Oscar Giner
Member #2,207
April 2002
avatar

Actually, the docs are a bit vague about this:

drawing_mode said:

This only affects the geometric routines like putpixel, lines, rectangles, circles, polygons, floodfill, etc, not the text output, blitting, or sprite drawing functions.

but if you go to the blitting and sprites section, only draw_trans_sprite (and draw_lit_sprite) mentions it's affected by the current drawing mode.

IIRC blit is not affected by draw_mode, but the docs say the opposite :-/ (but it wouldn't have sense to have two functions, draw_sprite and draw_trans_sprite).

Gideon Weems
Member #3,925
October 2003

Quote:

Actually, the docs are a bit vague about this

Eh? Maybe I'm missing something, but the snippet you posted says "not the text output, blitting, or sprite drawing functions".

Mariusz
Member #1,634
November 2001

Well, I had to replace blit with draw_trans_sprite function. Thanks to the fast response from Steve and Oscar. Thank you guys :-)

Oscar Giner
Member #2,207
April 2002
avatar

Quote:

Eh? Maybe I'm missing something, but the snippet you posted says "not the text output, blitting, or sprite drawing functions".

:-X It was very late when I read that.

Gideon Weems
Member #3,925
October 2003

Hahaha! I only laugh because I've been there...

Go to: