Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to properly use al_draw_scaled_bitmap?

This thread is locked; no one can reply to it. rss feed Print
How to properly use al_draw_scaled_bitmap?
thatrabbit
Member #18,225
August 2020

Hello. Allegro 5. Windows.

I am using al_draw_scaled_bitmap with 8-megabyte PNG.

I receive no errors when loading the PNG.

My call looks like:

al_draw_scaled_bitmap(storm, 0, 0, 100, 100, 50, 50, 200, 200, 0);

I assume that I am able to specify a bounding-rectangle for both source and destination.

The above code, when operating on the 8-MB file doesn't render anything from that bitmap. Everything else renders okay.

I resized the PNG to about 275-KB and the above operation works.

I assume it has to do with the size of the file?

I looked briefly and didn't see any mention of limitations in this regard.

Thoughts?

-- edit-1

I tried this:

al_set_new_display_option(ALLEGRO_MAX_BITMAP_SIZE, 10000, ALLEGRO_REQUIRE);

The docs say 2nd argument is "size", height and width, so I assume that value represents a square.

Either way, doesn't seem to give the desired effect.

-- edit-2

I tried:

al_set_new_display_option(ALLEGRO_MAX_BITMAP_SIZE, 1, ALLEGRO_REQUIRE);

Assuming my other bitmap would also not draw; it did draw. How does that function work?

-- edit-3

Oh no. I found this:

If a display bitmap is created, there may be limitations on the allowed dimensions. For example a DirectX or OpenGL backend usually has a maximum allowed texture size - so if bitmap creation fails for very large dimensions, you may want to re-try with a smaller bitmap. Some platforms also dictate a minimum texture size, which is relevant if you plan to use this bitmap with the primitives addon. If you try to create a bitmap smaller than this, this call will not fail but the returned bitmap will be a section of a larger bitmap with the minimum size. The minimum size that will work on all platforms is 32 by 32.

-- edit-4

Oh! Fortune smiles upon thee, Rabbit. For thou hast purchased assets whose original size works perfectly!

This means I will have to load 2 bitmaps to cover 1 spell. SO BE IT!

kenmasters1976
Member #8,794
July 2007

What's the resolution of your original PNG? Considering it's an 8 MB file, I guess it's several megapixels in size, so a block of 100x100 pixels could appear as a solid color square or even transparency, something that doesn't happen when you resize your PNG to a much smaller size.

thatrabbit
Member #18,225
August 2020

a block of 100x100 pixels could appear as a solid color square or even transparency

Hmm... You may have a point here. The image uses transparency, and that particular frame was mostly transparent with dark clouds on an entirely black background...

I'll give it a shot.

-- edit-1

And to answer your question, the original image is 960x6912.

-- edit-2

HA! You were totally right! I offset the rect to where the animation is basically white, and poof!

THANK-YOU. ;D

kenmasters1976
Member #8,794
July 2007

Keep in mind the arguments for al_draw_scaled_bitmap() include the width and height of the source and target areas in the respective bitmaps. That is, if you want to scale the full image to a 200x200 area, you'd have to call:

al_draw_scaled_bitmap(storm, 0, 0, 960, 6912, 50, 50, 200, 200, 0);

thatrabbit
Member #18,225
August 2020

include the width and height of the source and target areas

Aye! That was my hope.

In this case, the PNG is a sprite-sheet. Each frame is 192x192. And I want to scale each frame to the window.

I was using SDL 1.2 previously (jumped ship after trying to get sound working), and there was no blit_scaled function, so I scaled it in Gimp... yielding 160-MB file. :-/

Thank-you again!

Go to: