Hey I am writing an Allegro Program and I want to be able to test the frame rate. I am using the header file time.h to measure time. When it is supposed to display the framerate, it displays weird symbols. I figure this means that there must be a problem with my data conversions somewhere, but I can't figure it out. I'm stumped.
Here's my code:
Code:
#include <allegro.h>
#include <string>
#include <stdlib.h>
#include <time.h>
using namespace std;
void main()
{
int decimal;
int sign;
time_t newtime;
time_t oldtime;
double change;
double framerate=2.33637343;
string officialframerate;
char *rate;
char frames[]="Frame Rate: ";
allegro_init();
install_keyboard();
set_uformat(U_ASCII);
set_window_title("Greg's Game");
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
text_mode(-1);
newtime=clock();
while(!key[KEY_ESC]) //game loop
{
oldtime=newtime;
newtime=clock();
change=difftime(newtime, oldtime);
framerate=1.00/change;
rate=_ecvt(framerate, 10, &decimal, &sign); //converts double
//to c string
officialframerate.append(frames);
officialframerate.append(rate);
acquire_screen();
textout(screen, font, officialframerate.c_str(), 7, 5, 9); ////
//converts c++ string to c string for allegro
release_screen();
officialframerate.erase();
}
}
END_OF_MAIN()
Hopefully someone can help me out.
Thanks!