Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [Allegro5] Accelerated rotated bitmap

This thread is locked; no one can reply to it. rss feed Print
[Allegro5] Accelerated rotated bitmap
meh meh
Member #13,900
January 2012

Hey guys!

I'm still working on my little C++ game framework upon Allegro 5 and today, I've added the capability to rotate your Sprites. A Sprite is represented by a region of a Bitmap.

Actually, what I do when I render a Sprite :

Note: b is the instance of Bitmap used for this sprite, which returns its ALLEGRO_BITMAP* by a call to the method bitmap(). This Bitmap is actually a 512x512 bitmap with every sprites in it. This bitmap is a video-memory bitmap.

#SelectExpand
1if (rotAngle == 0.0f) { 2 al_draw_scaled_bitmap(b->bitmap(), 3 texCoords->topLeft().x(), texCoords->topLeft().y(), 4 texCoords->width(), texCoords->height(), 5 pos.x(), pos.y(), 6 s.x(), s.y(), 7 0); 8 } else { 9 // To rotate the bitmap, we should do it in a temporary bitmap 10 if (animHasChangedSinceLastRotation) { 11 if (bmp) { 12 al_destroy_bitmap(bmp); 13 } 14 bmp = al_create_sub_bitmap(b->bitmap(),texCoords->topLeft().x(),texCoords->topLeft().y(),texCoords->width(),texCoords->height()); 15 animHasChangedSinceLastRotation = false; 16 } 17 al_draw_scaled_rotated_bitmap(bmp, 18 rotCenter.x(),rotCenter.y(), 19 pos.x(),pos.y(), 20 s.x()/texCoords->width(),s.y()/texCoords->height(), 21 rotAngle, 22 0); 23 } 24}

As you can see, I create a sub-bitmap of the big one in order to rotate only the part that I need to draw rotated.
Do you think that by doing that, I'm doing an hardware-accelerated rotation ? Have you got any advice about this ?
It's my first use of sub-bitmaps and I'm not really sure to use them correctly.

Thanks!
r'm

PS: for those who remember my last post, I'm now able to render 18000 animated sprites at 50FPS! (10000 rotated&animated sprites at 50fps)

weapon_S
Member #7,859
October 2006
avatar

You could keep all the sub-bitmaps as if they were all separate images. Why does it exclude unrotated objects from animation? Otherwise seems alright.

meh meh
Member #13,900
January 2012

Actually, by using al_draw_scaled_bitmap when I don't need to rotate or tint, it allows me to directly draw a part of a bitmap without creating a sub-bitmap, which seems faster if my test were ok.
Thank you for your answer!

r'm

SiegeLord
Member #7,827
October 2006
avatar

meh meh said:

Do you think that by doing that, I'm doing an hardware-accelerated rotation ?

Yes

Quote:

Have you got any advice about this ?

Two things:
1. the unstable branch of A5 has al_draw_scaled_rotated_bitmap_region.
2. You could use transformations to avoid creating the temporary bitmap, if you think it's a bottleneck (it probably isn't).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

meh meh
Member #13,900
January 2012

Okay thank you for the information!

Go to: