Page 1 of 1

Transparency with dsb_bitmap_blit?

Posted: Mon May 07, 2012 3:44 pm
by Gambit37
I have an image with some power-pink pixels that i'm blitting onto another bitmap with dsb_bitmap_blit.

The power pink stays pink and is not made transparent. Also, alpha images don't retain their transparency either, the trans bits are rendered white.

Is this a bug or am I doing something wrong?

Re: Transparency with dsb_bitmap_blit?

Posted: Mon May 07, 2012 6:19 pm
by Sophia
This is intended; dsb_bitmap_blit is "dumb" and is solely for copying bitmaps.
If you want to actually have these features, dsb_bitmap_draw is the command you want. :)

Re: Transparency with dsb_bitmap_blit?

Posted: Mon May 07, 2012 6:31 pm
by Gambit37
Ah, but I want to draw only part of the bitmap (width based on a dynamic value) and dsb_bitmap_draw doesn't seem to support all those extra parameters found in dsb_bitmap_blit?

Re: Transparency with dsb_bitmap_blit?

Posted: Mon May 07, 2012 6:42 pm
by Sophia
This is actually a limitation of Allegro 4; for some reason it only lets you apply the vast majority of effects (like alpha blending etc.) to bitmaps if you draw the whole thing. Of course, there are ways around that (you could do it yourself, even, by using these two drawing functions in combination) but it would be faster and simpler to just have DSB do it automatically. So, I can add the extra parameters as optional ones.

Re: Transparency with dsb_bitmap_blit?

Posted: Mon May 07, 2012 6:48 pm
by Gambit37
Ooh, that would be great, thanks.

Out of interest, what would be the way of doing it using current functions? I can't quite get my head around it. Would I create a new bitmap, render the full width, then use that as the source for the blit function? Do I have to do the first part off screen or something?

EDIT: I sort of got it to work, but the transparent parts flicker:

Code: Select all

b_width = (max_bar_width / xp_levels) * level
bmp_bar = dsb_new_bitmap(b_width, 11)
dsb_bitmap_draw(gfx.selector_statbar1, bmp_bar, 0, 0, false)
dsb_bitmap_blit(bmp_bar, bmp, 0, 0, 350, y, (150/xp_levels) * level , 11)

Re: Transparency with dsb_bitmap_blit?

Posted: Mon May 07, 2012 7:00 pm
by Sophia
You had the right idea, you just got the order wrong.
You dsb_bitmap_blit (i.e., make a dumb copy) of the wanted part onto your temporary bitmap. This will also blindly copy all power pink, alpha channels, and so on. Then you dsb_bitmap_draw your temporary bitmap onto your target, where it will render alpha and so on properly.

Re: Transparency with dsb_bitmap_blit?

Posted: Mon May 07, 2012 7:08 pm
by Gambit37
Woo hoo, thanks for the pointers, I got it to work :-)

Code: Select all

bar_width = (max_bar_width / xp_levels) * level
bmp_bar = dsb_new_bitmap(bar_width, 11)
dsb_bitmap_blit(gfx.selector_statbar1, bmp_bar, 0, 0, 0, 0, bar_width, 11)
dsb_bitmap_draw(bmp_bar, bmp, 350, y, false)
I'm rather enjoying this coding malarkey. I know I'm only doing basic stuff, but it's satisfying getting stuff to work :-)

Re: Transparency with dsb_bitmap_blit?

Posted: Mon May 07, 2012 7:18 pm
by Sophia
It is satisfying getting stuff to work! :mrgreen:

I'll still implement the optional parameters for dsb_bitmap_draw, though, so you don't have to mess with this all the time.