Double Buffering
ErrorTerror

My problem is that when I am using double buffering and color depth bigger than 8bit the framerate drops heavily. Even when using 640x480x16 framerate is only 20-25fps. And there is only small ball moving on the screen. I am using Dev-C++ and Mingw32, but i had the same problem with djgpp.

An Ly

Since a larger number of bits are required to tell a colour in 16bit mode compared to 8 (twice as many in fact), you would have to shuffle more information from a bmp to screen at each screen write. Hence, you would expect the frame rate to drop by at least half if double buffering.

Thomas Harte

Unless by double buffering you mean hardware double buffering (in Allegro terms creating a couple of video bitmaps and switching between them) in which case both types of double buffering should be an identical speed until you start drawing things, and then you should be able to draw one 16bpp sprite in less than the time it takes to draw two same sized 8bpp sprites.

That said, the advantages of a hardware double buffer reduce greatly (and can be slower than drawing everything in memory and blitting once) if you have large amounts of overdraw. Although overdraw probably isn't too great if your game is 2d . . .

Murray Bozinsky

when you are coding under windows, system-bitmaps or video-bitmaps or even both might be hardware-accelerated (check the testtool->acceleration features). using normal memory-bitmaps in 640x480x16 and double buff. i also get 20-30 fps, but with video-bitmaps i get 120-130 fps.

/Murray Bozinsky

ErrorTerror

mboz,

Thanks for your tip. I changed double buffer to video bitmap and the framerate is now 750-800 fps. But the is now lot of flickering, any ideas?

ErrorTerror

...And I get those 750-800 fps using 1024x768x16 resolution.

tomas unosson

Is there an example of this? Could someone put out a sample of how to use videobitmaps. Would be great.

Mike Farrell

you could use system bitmaps. I heard they are faster...(or is that only under windows)??

lillo

lemur, you can find an example on using video bitmaps directly into the Allegro distro. It's the example program examples/exaccel.c (assuming you've a WIP Allegro version)
Other than this, I can say video bitmaps can be used as you do with normal bitmaps, but you must keep a few things in mind:
- if you don't have hardware acceleration on your platform, video bitmaps are slower than normal memory bitmaps
- accessing video bitmap memory directly isn't as easy as with memory bitmaps; generally you can't use a syntax like bitmap->line[y][x] to access a pixel, as you have to take care of possible bank switching and other system specific tasks. Take a look at the Allegro docs, under the "Direct access to the framebuffer" section (if I remember well). Anyway, this doesn't apply as long as you don't want to access bitmap data directly; this means that you don't have to worry about this if you use putpixel, draw_sprite or any other normal Allegro function.
- when you first allocate a video bitmap, its memory is taken from the first available place in video RAM; this means it could also be a piece of the screen currently displayed. Don't worry; all you have to do is to avoid using the "screen" bitmap while using video bitmaps. You can do something like this (assuming you're in 640x480):
BITMAP *my_screen = create_video_bitmap(640, 480);
and then use
show_bitmap(my_screen);
everytime you want your bitmap to be displayed on the screen.

proftilley

If you are moving a few things around a large area, you might want to be using dirty rectangles.

tomas unosson

//PAGE FLIPPING
Is it something like this you do ?
I can only reach Fps 60 with page flipping in DOS.
//-----------------------------
#include <stdio.h>
#include <string.h>
#include "allegro.h"
#define ScreenSizeX 800
#define ScreenSizeY 600
BITMAP *buffer;
BITMAP *buffer2;
BITMAP *b2;
BITMAP *BackPic;
int main()
{

allegro_init();
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT, ScreenSizeX, ScreenSizeY, 0, 0);
buffer = create_video_bitmap (ScreenSizeX,ScreenSizeY);
buffer2 = create_video_bitmap (ScreenSizeX,ScreenSizeY);
BackPic = load_pcx ("backpic.pcx",NULL);
while (!(key[KEY_ESC]))
{

b2=buffer;
buffer=buffer2;
buffer2=b2;
blit(BackPic,buffer, 0,0, 0,0,ScreenSizeX,ScreenSizeY);

// do 500 moving balls or something

show_video_bitmap(buffer);
} //END while

allegro_exit();
} //End main

Thread #148701. Printed from Allegro.cc