Increasing the speed of transitioning from one image into another?

What I'm doing right now is fading one menu screen into another when a menu item is selected. Problem is, it's really slow. The images are 800x600. I know it's the images that are the problem because when I do fade in/out from/to black, the speed is just fine. It's only when the image has something in it that the slowdown occurs.

Here's the function I'm using:

1void objGfx::TransitionFade(BITMAP* endImage, int fadeSpeed)
3 BITMAP* startImage = create_bitmap(SCREEN_W, SCREEN_H);
4 blit(Screen->Buffer(), startImage, FULL_SCREEN, SCREEN_W, SCREEN_H);
6 COLOR_MAP transTable;
7 color_map = &transTable;
9 if (fadeSpeed <= 0)
10 {
11 fadeSpeed = 16;
12 }
14 install_int(TickTimer, FADE_TIMER);
16 int i = 0;
18 while (i < 256)
19 {
20 if (tick == true)
21 {
22 tick = false;
24 set_trans_blender(0, 0, 0, i);
25 blit(startImage, Screen->Buffer(), FULL_SCREEN, SCREEN_W, SCREEN_H);
26 draw_trans_sprite(Screen->Buffer(), endImage, 0, 0);
28 Screen->Update();
30 i += fadeSpeed;
31 }
32 }
34 blit(endImage, Screen->Buffer(), FULL_SCREEN, SCREEN_W, SCREEN_H);
36 remove_int(TickTimer);
38 destroy_bitmap(startImage);
39 destroy_bitmap(endImage);

Any tips to speed things up?

Simon Parzer

Your problem is obviously draw_trans_sprite. It's an Allegro function and therefore uses software rendering. That means that it has to check every pixel of your image and manually blend it with the correspondending pixel from the new image (800x600 => 480000 pixels).
To speed things up, you should use hardware rendering (through OpenLayer or OpenGL?), which makes use of your graphic card instead of the CPU. This is much faster, but it requires some kind of 3D hardware.


First and probably the simpliest speedup is to create startImage and endImage once, not in every frame. Also a lot of speed can be gained if you don't use video bitmaps with blending. That means you first do all the drawin in memory bitmaps and blit the result to screen.

If you need ~30-250% faster blending you might want to try compiling Allegro using plain-c functions. I've seen that draw_trans_sprite can be much faster in c-mode:

Another thing that can speed things up is to use draw_trans_rle_sprite() but that only works good for read-only images.

In Linux you can compile Allegro in C mode with ./configure --enable-asm=no. I don't know how you can do it in windows.


Or use fblend.

But switching to allegrogl or openlayer is probably the best choice.


or do as i did, and write a blender in SSE2, works awesomely fast!
but not as fast as hardware acceleration, which you should be trying.

Thread #585866. Printed from