Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Transparancy Difference on windows and ubuntu

This thread is locked; no one can reply to it. rss feed Print
Transparancy Difference on windows and ubuntu
dratone
Member #16,642
March 2017

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
Member #270
April 2000

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?

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Elias
Member #358
May 2000

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.

--
"Either help out or stop whining" - Evert

dratone
Member #16,642
March 2017

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
Member #270
April 2000

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)?

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

dratone
Member #16,642
March 2017

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

Chris Katko
Member #1,881
January 2002
avatar

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.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Go to: