- Online Community Forums » Programming Questions » FPS Drop (probably an easy fix)

This thread is locked; no one can reply to it. rss feed Print
FPS Drop (probably an easy fix)
Member #15,613
May 2014

I'll preface this by saying I'm pretty new to allegro, and a pretty bad programmer overall. The attatched code has been created expressly to reproduce my issue, and isn't currently in use in any project. I'm using the current stable release (5.0.10). I'm statically linking the -static-mt files with MinGW.

Description of my issue:
When I compile and run the attatched code, the game will run as normal (40fps) for around 4 seconds, and then suddenly drop down to 14fps, and remain like that for the rest of the time the game is running. I'm trying to figure out if this is an issue with my computer, or with the way I am coding... Hopfully someone can help me with this issue.

Neil Roy
Member #2,229
April 2002

You should use


my code here


and past examples directly into messages in here in the future, makes life easier = faster replies... here's the code for other's convenience...

1#include <allegro.h> 2#include <allegro_image.h> 3#include <allegro_font.h> 4#include <allegro_ttf.h> 5 6int MAXIMAGES = 2; //only 2 images used in this test 7int MAXFONTS = 1; //font used to draw the fps 8int ScrW = 800; //display width 9int ScrH = 640; //display height 10 11int main (int argc, char *argv[]) 12{ 13 14ALLEGRO_DISPLAY *gamedisp;//display 15ALLEGRO_BITMAP* images [MAXIMAGES];//array of images 16ALLEGRO_FONT* fonts [MAXFONTS];//same but for fonts 17 18al_init(); 19al_init_image_addon(); 20 21ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); 22al_set_path_filename(path,"/bin/images/title.png"); 23images[0]=al_load_bitmap(al_path_cstr(path,'/')); 24al_set_path_filename(path,"/bin/images/byval.png"); 25images[1]=al_load_bitmap(al_path_cstr(path,'/')); 26 27gamedisp=al_create_display(ScrW,ScrH); 28 29al_init_font_addon(); 30al_init_ttf_addon(); 31al_set_path_filename(path,"/bin/fonts/font.ttf"); 32fonts[0]=al_load_font(al_path_cstr(path,'/'),14,0); 33 34float fps=0; //fps is 0 before any frames are rendered 35double fpstime = al_get_time(); // used to compare frame times and give FPS 36 37 while (1) 38 { 39 al_clear_to_color(al_map_rgb(0,0,0)); 40 al_draw_bitmap(images[0],259,248,0); //draws image 1 so its centered 41 al_draw_bitmap(images[1],(ScrW/2),(ScrH/2)+30,0); //draws image 2 so it fits with image 1 42 al_draw_textf(fonts[0],al_map_rgb(255,255,255),0,0,0,"FPS: %f",fps);//print fps 43 al_flip_display();//flip 44 45 double new_time = al_get_time(); 46 fps = 1.0f/(new_time-fpstime); 47 fpstime = new_time;//new fps 48 } 49 50 51 52return 0; 53}

“I love you too.” - last words of Wanda Roy

Edgar Reynaldo
Major Reynaldo
May 2007

One thing I see is that you are loading your bitmaps before you create your display. Without a display set as the current context you cannot create video bitmaps, so they are being created as memory bitmaps. Load your bitmaps after you create your display and see if that fixes things.

Member #15,613
May 2014

That ended up doing the trick, thanks a lot.

Go to: