Increasing the speed of transitioning from one image into another?
BrknPhoenix

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)
2{
3 BITMAP* startImage = create_bitmap(SCREEN_W, SCREEN_H);
4 blit(Screen->Buffer(), startImage, FULL_SCREEN, SCREEN_W, SCREEN_H);
5
6 COLOR_MAP transTable;
7 color_map = &transTable;
8 
9 if (fadeSpeed <= 0)
10 {
11 fadeSpeed = 16;
12 }
13 
14 install_int(TickTimer, FADE_TIMER);
15
16 int i = 0;
17
18 while (i < 256)
19 {
20 if (tick == true)
21 {
22 tick = false;
23
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);
27
28 Screen->Update();
29
30 i += fadeSpeed;
31 }
32 }
33
34 blit(endImage, Screen->Buffer(), FULL_SCREEN, SCREEN_W, SCREEN_H);
35
36 remove_int(TickTimer);
37
38 destroy_bitmap(startImage);
39 destroy_bitmap(endImage);
40}

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.

HoHo

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:
http://www.allegro.cc/forums/thread/474843/477775#target
http://www.allegro.cc/forums/thread/474843/478181#target

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.

deps

Or use fblend.

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

A J

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 Allegro.cc