Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Alpha Blending problems

This thread is locked; no one can reply to it. rss feed Print
Alpha Blending problems
thehuggableone
Member #7,625
August 2006

Ok, I'm working on a platform shooter, and the edges of my graphics are a little pixelated, so, as I did in a backgammon game I wrote not too long ago, I'm using a function that creates an "anti-aliased" sprite by merging the real sprite with a separate alpha channel (same shape, but black and white with blurred edges). Below is almost exactly the same function I used for my backgammon game, however this one keeps giving me my sprite rendered as a black box.

I don't know what's going on. Masked draw is simply a call to masked blit. Is there something I'm missing? I've scoured my backgammon code and can't figure out what's going on. It would help if I actually understood what's going on with the transparency stuff, but it's not a necessity I don't guess.

I tried making a call to set_alpha_blender() before printing and even calling draw_trans_sprite() but that didn't work either. Any help would be wonderful, either in fixing my problem or suggesting a better way to do what I'm trying to do. I AM fairly new to game programming and could use all the help I can get.

Thanks

--Wes

1 
2void main()
3{
4 /*MAIN STUFF*/
5 daggy[0] = makeMasked("data/images/daggy_sprite.bmp","data/images/daggy_alpha.bmp", 128);
6 daggy[1] = makeMasked("data/images/daggy_sprite2.bmp","data/images/daggy_alpha2.bmp", 128);
7 
8 CSprite playerCharacter(daggy,1,0,0,0,0,0,100,100,0);
9 FixPlatformCollision(playerCharacter,background);
10 playerCharacter.update();
11 FixBoundsCollisions(playerCharacter);
12
13 playerCharacter.masked_draw(buffer);
14 
15 blit(buffer,screen,0,0,0,0,SCREENW,SCREENH);
16 while(!key[KEY_ESC}){}
17 /*MAIN STUFF*/
18}
19END_OF_MAIN();
20 
21BITMAP* makeMasked(char* image_file, char* alpha_file, int alpha)
22{
23 BITMAP *tempPiece;
24 BITMAP *sprite;
25 int c, a;
26
27 tempPiece = load_bitmap(image_file,NULL);
28 sprite = load_bitmap(alpha_file,NULL);
29
30 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
31 set_write_alpha_blender();
32
33 for (int y=0; y<sprite->h; y++) {
34 for (int x=0; x<sprite->w; x++) {
35 c = getpixel(sprite, x, y);
36 a = getr(c) + getg(c) + getb(c);
37 a = MID(0, a/2-alpha, 255);
38 putpixel(tempPiece, x, y, a);
39 }
40 }
41
42 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
43
44 destroy_bitmap(sprite);
45 return tempPiece;
46}

Arthur Kalliokoski
Second in Command
February 2005
avatar

I'm just taking a wild guess here, but stick in a couple lines in the program to save the masked bitmaps to .tga files, then make a little allegro utility to display these and call getpixel() on mouse clicks to display the rgba values.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Go to: