Transparency with dsb_bitmap_blit?

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Transparency with dsb_bitmap_blit?

Post 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?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Transparency with dsb_bitmap_blit?

Post 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. :)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Transparency with dsb_bitmap_blit?

Post 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?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Transparency with dsb_bitmap_blit?

Post 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.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Transparency with dsb_bitmap_blit?

Post 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)
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Transparency with dsb_bitmap_blit?

Post 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.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Transparency with dsb_bitmap_blit?

Post 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 :-)
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Transparency with dsb_bitmap_blit?

Post 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.
Post Reply