(fixed in 0.78) sys_render_other rendering woes. (0.77)

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: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

(fixed in 0.78) sys_render_other rendering woes. (0.77)

Post by Gambit37 »

After finally getting my sys_render_other to behave for 0.77, I've discovered new problems with how alpha channels and blitting behave. I don't know if I'm doing something wrong, so here's some pseudo code to show various setups and the results. I've reduced down to the pertinent code for brevity. Note that the size of the bmp received by sys_render_other from the gui_info table is the full size of the viewport/inventory (448,272):

================================================================

#1 gives perfect results with non-alpha 8-bit bitmaps. My popup is rendered correctly over the inventory:

Code: Select all

function sys_render_other(bmp, gui_name, frozen)
	dsb_bitmap_clear(bmp, color.powerpink)
	dsb_bitmap_draw(gfx.ui_stats_popup, bmp, 192, 38, false)
	{render out the stats text}
end
Image

================================================================

#2 I replace my popup with a 32-bit bitmap which contains alpha transparency. It gets blended with the powerpink of the cleared "parent" bitmap:

Code: Select all

function sys_render_other(bmp, gui_name, frozen)
	dsb_bitmap_clear(bmp, color.powerpink)
	dsb_bitmap_draw(gfx.ui_stats_popup_ALPHA, bmp, 192, 38, false)
	{render out the stats text}
end
Image

================================================================

#3 I change the bitmap clearing method to use the alpha clearing method instead (that you previously suggested in a different thread). Now the popup renders its alpha correctly, but subsequent drawing onto this bitmap is also affected (the text is now transparent!). Note that other gui_zones are now not rendered at all (the red circle):

Code: Select all

function sys_render_other(bmp, gui_name, frozen)
	bitmap_clear_alpha(bmp, color.black)
	dsb_bitmap_draw(gfx.ui_stats_popup_ALPHA, bmp, 192, 38, false)
	{render out the stats text}
end
Image

================================================================

#4 Let's repeat example #3, but BLIT the alpha popup rather than DRAW it. Same results as #3:

Code: Select all

function sys_render_other(bmp, gui_name, frozen)
	bitmap_clear_alpha(bmp, color.black)
	dsb_bitmap_blit(gfx.ui_stats_popup_ALPHA, bmp, 0, 0, 192, 38, 284, 262)
	{render out the stats text}
end
Image

================================================================

#5 Let's repeat example #4, but clear the parent bitmap to powerpink again, rather than the alpha clear to black. Other gui_zones now show up again correctly (the main stats bottom left), but the popup is still mangling the text:

Code: Select all

function sys_render_other(bmp, gui_name, frozen)
	dsb_bitmap_clear(bmp, color.powerpink)
	dsb_bitmap_blit(gfx.ui_stats_popup_ALPHA, bmp, 0, 0, 192, 38, 284, 262)
	{render out the stats text}
end
Image

================================================================

Hopefully you can help me either (a) clear up my code to work correctly or (b) fix what might be a bug...? I'm pretty confused by all this now...! :?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: sys_render_other rendering woes. (0.77)

Post by Sophia »

Ok, so! Two things!

First, the text had so many problems because text was always drawn with an alpha of 0. This isn't a problem with powerpink-based bitmaps (since alpha is ignored) but of course it causes problems if you're trying to draw onto a bitmap with alpha channels. Allegro 4 unfortunately cannot elegantly handle fonts with alpha channels, so as of 0.78 I've changed it to always draw text with an alpha of 255.

Second, that bitmap_clear_alpha function is a bit of a hacky workaround, because it only changes one pixel and relies on DSB to auto-detect that you're now using an alpha channel. For 0.78 I've also added a proper dsb_bitmap_clear_alpha function that takes an alpha value to clear the (entire) bitmap to and properly asserts that the bitmap should respect it.

With the text rendering fix and changing the code to use the new dsb_bitmap_clear_alpha I get something that looks like I think you intended, so I'll call this one fixed for 0.78 for the moment.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: sys_render_other rendering woes. (0.77)

Post by Gambit37 »

Aaaaaaahahahaha! Awesome, thank you so much. :) I thought I was going mad. (Perhaps I still am but that's another issue entirely -- 2020 and all that!)
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: sys_render_other rendering woes. (0.77)

Post by Sophia »

If you're using 0.78 and up, if you change bitmap_clear_alpha to wrap dsb_bitmap_clear_alpha your code shouldn't need any modification.

Code: Select all

function bitmap_clear_alpha(bmp, color)
   dsb_bitmap_clear_alpha(bmp, color)
end
Post Reply