|
[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. 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. Thanks! 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
|
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. r'm |
SiegeLord
Member #7,827
October 2006
|
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: "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
meh meh
Member #13,900
January 2012
|
Okay thank you for the information! |
|