What is wrong with my code? My fps time is not working.I found two errors in my code.
Error 1 error C3861: 'install_timer_ex': identifier not found.
Error 2 error C3861: 'textmode': identifier not found.

#include <allegro.h>
BITMAP* buffer = create_bitmap(480,480);

 volatile int fps = 0;
 volatile int avg_fps = 0;
 volatile int last_fps = 0;
 
 void fps_timer(){
	last_fps=fps;
	fps=0;
	avg_fps=(avg_fps*last_fps)/2;
}
 
 int main(){
	allegro_init();
	install_timer();
	set_gfx_mode( GFX_AUTODETECT, 480, 480, 0, 0);

	install_timer_ex(fps_timer,SECS_TO_TIMER(1));

while(!key[KEY_ESC]){
	//drawing code//

	fps++;
	//textout fps, avgfps, lastfps, etc//
	textmode(makecol(0,0,0));
	textprintf(buffer,font,0,0,makecol(0,0,0),"FPS: %i  Average FPS: %i", last_fps, avg_fps);

}
 }

Dani AI

Generated

Two separate issues are causing the compile errors you saw. The timer routine name in Allegro 4 is not install_timer_ex — use install_int_ex (or install_int) to register a handler. Also textmode is not part of Allegro; it’s a DOS/conio function from Turbo/Borland-style libraries, so the compiler won’t find it. (liballeg.org)

Timer handlers must be kept tiny and must be locked for use from an interrupt. Declare your counters volatile, lock them with LOCK_VARIABLE, lock the function with LOCK_FUNCTION (and use END_OF_FUNCTION after the handler), then call install_int_ex(...). Example pattern (names changed from the original to avoid duplication):

volatile int fps_count = 0, fps_last = 0;

void timer_tick(void)
{
    fps_last = fps_count;
    fps_count = 0;
}
END_OF_FUNCTION(timer_tick)

// during init:
install_timer();
LOCK_VARIABLE(fps_count);
LOCK_VARIABLE(fps_last);
LOCK_FUNCTION(timer_tick);
install_int_ex(timer_tick, SECS_TO_TIMER(1));

Keep graphics/text calls out of the timer; only update counters or flags inside it. (liballeg.org)

For text output, replace attempts to use textmode with Allegro’s text functions that accept foreground/background arguments — e.g. textprintf_ex or textout_ex. Use -1 for a transparent background, or pass a makecol(...) value for a filled background. Example:

textprintf_ex(buffer, font, 0, 0,
              makecol(255,255,255), -1,
              "FPS: %d  Avg: %d", fps_last, avg_fps);

Also: call install_keyboard() before you rely on key[...], and create your double-buffer (create_bitmap) after you’ve set color depth / graphics mode. (unix.com)

Small bug fix note: avg_fps = (avg_fps * last_fps) / 2 is incorrect for averaging — use avg_fps = (avg_fps + last_fps) / 2 (or a proper running average) instead.

I have never used allegro, but my guess is:

- There is no function called install_timer_ex (maybe you mean install_int_ex?)
- There is no function called textmode (seems redundant)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.