Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » FBlend transparency drawing not perfect?

Credits go to Neil Walker for helping out!
This thread is locked; no one can reply to it. rss feed Print
FBlend transparency drawing not perfect?
Stefan Hendriks
Member #1,957
March 2005

Recently i switched to FBlend (0.5) to speed my transparency drawing routines. Immidiatly some things sped up greatly (especially for fading in/out in 16/32 bit).

However, i also draw shadows for units, and use a mask for that. The only line i basicly changed is a draw_trans_sprite() line into an fblend_trans(). What i do see now is that the 'box' (temp bitmap where unit is drawn and processed before its being drawn at the screen) is also visible. But, it should be skipped since it is RGB (255,0,255) (purple).

Here is a code snippet; which works 100% fine with Allegro routines, but changing it to fblend, does show me my temp bitmap. It is not very clearly visible, yet its there and it makes my other images look odd (especially when a lot of units are drawn next to each other).

1 
2// bitmap creation
3 BITMAP *temp;
4 BITMAP *shadow;
5 temp = create_bitmap_ex(8, 64*2,64*2); // 8 bits to copy from datafile
6 shadow = create_bitmap(64,64); // current bitdepth to draw proper shadow
7
8 clear_bitmap(temp);
9 clear_to_color(shadow, makecol(255,0,255));
10 
11// .... some other code snipped out....
12 
13// DRAW SHADOW
14 if (units[iType].shadow)
15 {
16 if (iType != CARRYALL)
17 blit((BITMAP *)units[iType].shadow, shadow, start_x, start_y, 0, 0, bmp_width, bmp_height);
18 else
19 blit((BITMAP *)units[iType].shadow, shadow, start_x+2, start_y+2, 0, 0, bmp_width, bmp_height);
20 
21// NOTE: shadow = current bitdepth ofcourse.
22 
23 draw_trans_sprite(bmp_screen, shadow, ux-startpixel,uy);
24 //fblend_trans(shadow, bmp_screen, ux-startpixel, uy, 128);
25 }

Is this a known problem? It also seems to affect my structures if i use fblend. If i must, i will re-use draw_trans sprite, and only use fblend for other blending techniques.

Neil Walker
Member #210
April 2000
avatar

fblend_trans does indeed take into account the mask colour. Regarding, (BITMAP *)units[iType]

You are blitting units onto shadow which is in effect making your clear code pointless. So more than likely either units is 8bpp and the mask is black or not quite 255,0,255. Use the masked blit.

But I would also check what colour conversion method you've applied as mixing colour depths does different things depending on set_colour_conv

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Stefan Hendriks
Member #1,957
March 2005

Actually it is the other way around:

There is a shadow bitmap, which is the bitdepth of the game (16 bit).
There is the unit bitmap, which is the bitdepth of 8.

Using the player palette the unit will be drawn, the unit itself is from the datafile, copied the right part of it (facing) and blitted to TEMP. This will do the proper color conversion. From there on, i draw_sprite it at the screen.

The shadow is 16 bit, which is thus also blitted, and then draw_trans_ sprited to the screen directly (bmp_screen).

So:

SHADOW bitmap in my game is 16 bit (also in datafile)
UNIT bitmap in my game is 8 bit (also in datafile)

therefor i use for UNIT the 8 bit mask color index 0. And for SHADOW the 16/32 bit mask color rgb (255,0,255).

Neil Walker
Member #210
April 2000
avatar

How about attaching an image of the fault.

Saying that I didn't read your code properly and I've only ever used fblend_trans for tinting my screens and haven't used it with masks. But I do know that the fblend_fade doesn't work with masks but that is by design and fblend_trans does state it accounts for the mask.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Stefan Hendriks
Member #1,957
March 2005

Attached is a picture where you can see at the left, a slightly ligher rock then at the right.

The rock at the right is a bit darkened due fblend. The units are 32x32, but their temp bitmap is 64x64. Especially when close, some parts of rock get dark.

It is hard to see now, but especially at fullscreen you see boxes moving , and thats a pitty.

You are right though, that is the magic pink that is not being drawn , somehow gets tinted a bit darker...

EDIT: I found this bug is already known:
http://sourceforge.net/tracker/index.php?func=detail&aid=642691&group_id=36726&atid=417692

Neil Walker
Member #210
April 2000
avatar

I guess it's the same bug as with the fade then. Like I said, I only used fblend_trans for doing rectangles and found the bug with fade but assumed it was limited to this as fade was a new addition.

The problem I can see is that while it might be easy to make a fix in the C code, assembly is used in some circumstances and I haven't a clue how to even look at that.

The best bet is to hope Bob reads this ;)

I was using fblend to do fades but found this magic pink problem. I got round it by doing the blend then re-applying all the magic pink pixels afterwards. On timings, it worked out no faster than allegro blenders so I dumped fblend.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Stefan Hendriks
Member #1,957
March 2005

Yeah, praying that Bob reads this! :)

Well, i get around this problem by just using fblend for large images that fade(and fade in/out into each other using transculency or whatever).

I also darken pictures by fblend_trans , like unavailabel buttons or buildings/units you cannot buy due not enough money. It will not give me problems there.

For units i will simply not use it then, as goes for my shroud drawing. Structures are seperated classes with each their drawing function (since they differ, have different effects, etc). So i will do fblend where possible, and use draw_trans when it fails.

The FPS gain will not be huge, but it will be some, and that is enough for me.

Go to: