Page 1 of 1

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

Posted: Mon Nov 02, 2020 1:44 pm
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...! :?

Re: sys_render_other rendering woes. (0.77)

Posted: Mon Nov 02, 2020 9:46 pm
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.

Re: sys_render_other rendering woes. (0.77)

Posted: Mon Nov 02, 2020 10:50 pm
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!)

Re: sys_render_other rendering woes. (0.77)

Posted: Wed Nov 11, 2020 1:03 am
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