Transparancy Difference on windows and ubuntu
dratone

Hi,

I'm developing a game and, while i'm not new to game development, its the first time I'm using allegro5.

There seems to be a weird difference between Windows and Ubuntu though:

I'm building an image using a few layers. Each layer can have transparency and this is defined in the image (.png files with a transparency channel).

It is working without any weird issues on windows:
https://www.dropbox.com/s/6cx492ihw4fxrwk/windows1.png?dl=0

But, on ubuntu - the transparency is replaced with, I think, random memory:
https://www.dropbox.com/s/v60czqmfnimj4sv/ubuntu1.png?dl=0

Does anybody have any hints as to what this could be? I've run out of ideas :-(

Bruce Perry

Drawing order and z-buffer issue? Transparency doesn't modify the pixels from what they were when uninitialised, but does preclude further drawing in those areas?

Elias

How are you loading your images? Windows usually sets uninitialized memory to 0 - so you may simply not initialize something, but on Windows you don't notice as easily.

[edit:] Specifically, al_create_bitmap() will create an uninitialized bitmap, you have to clear it for it to become 0 and not random memory.

dratone

Hi,

Elias said:

[edit:] Specifically, al_create_bitmap() will create an uninitialized bitmap, you have to clear it for it to become 0 and not random memory.

That was indeed the issue. Thanks!

What I was doing was load the image file and then cut out the tile i needed so I didn't have to calculate that every time.. Meaning I did indeed create a new bitmap that way.

After adding an initialization it worked like a treat. Thanks!

BTW: Is there any better way then doing this:

#SelectExpand
1ALLEGRO_BITMAP* newtile = al_create_bitmap(width, height); 2ALLEGRO_BITMAP* old = al_get_target_bitmap(); 3al_set_target_bitmap(newtile); 4al_clear_to_color(al_map_rgba_f(0,0,0,0)); 5al_draw_bitmap_region(Sheet, tOffset.x, tOffset.y, Size.x, Size.y, 0, 0, 0); 6al_set_target_bitmap(old);

If not I'll probably just create a utility function for it, but I was wondering if I was missing something.

Bruce Perry

You might find al_create_sub_bitmap useful here. It has GPU advantages since internally Allegro can tell the GPU to do loads of draw operations from the same texture instead of many different ones.

By the way, Elias, wouldn't all platforms initialise memory to zero upon first handing it to a process, for security reasons? And then all platforms would leave it uninitialised if reallocating it when it already belonged to the process in the past (since the OS isn't even involved at this stage)?

dratone

Thanks for the tip. I'll try to keep that in mind and use sub bitmaps where possible.

Chris Katko
Elias said:

[edit:] Specifically, al_create_bitmap() will create an uninitialized bitmap, you have to clear it for it to become 0 and not random memory.

Even if that's the OS case, that doesn't seem like it should be Allegro's case. If it's not a huge performance reason, we should probably default to calling clear_to_color inside al_create_bitmap. Returning a completely different bitmap state on a different OS sounds like it should be a different function name.

Thread #616777. Printed from Allegro.cc