Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Allegro al_draw_textf

$
0
0
Hi! I'm writing a very simple program using Allegro to play with fonts for a class project. It runs well with one exception, it's not displaying a variable value inside my textf statement. My professor has looked it over and doesn't understand why, so we are a bit stumped. Are we missing something obvious? The output screen should say "This message will self destruct in 10 seconds", but instead it says "This screen will self destruct in seconds".

I've spent a chunk of time this morning reading the Allegro manual and a couple of forum posts, but I'm not finding anything wrong with my code. The textf block is on lines 45-50 I believe. Thank you!

Here is the short version of where I think the problem lies:


	int screen_w = al_get_display_width(display);
	int screen_h = al_get_display_height(display);
	int restTime = 10;

	al_draw_textf(font36, al_map_rgb(255, 255, 255), screen_w/2, screen_h/2, ALLEGRO_ALIGN_CENTRE,
		"This screen will self destruct in %i seconds", restTime);




And here is the entire file:

//FILE : FontText.cpp

//PROG : Mickie Maxey

//PURP : Test Fonts and compiler settings in Allegro to gain experience

#include <allegro5\allegro.h>
#include <allegro5\allegro_font.h>
#include <allegro5\allegro_ttf.h>
#include <allegro5\allegro_native_dialog.h>

int main(void)
{

	ALLEGRO_DISPLAY *display = NULL;

	if(!al_init())
	{
		al_show_native_message_box(NULL, NULL, NULL, "Allego Init FAIL!!!", NULL, NULL);

		 return -1;
	}


	display = al_create_display(640, 480);

	if(!display)
	{
		al_show_native_message_box(NULL, NULL, NULL, "Display FAIL!!!!!", NULL, NULL);

		return -1;
	}



	al_init_font_addon();
	al_init_ttf_addon();


	ALLEGRO_FONT *font36 = al_load_font("orange juice.ttf", 36,0);

	al_clear_to_color(al_map_rgb(0,0,0));


	int screen_w = al_get_display_width(display);
	int screen_h = al_get_display_height(display);
	int restTime = 10;

	al_draw_textf(font36, al_map_rgb(255, 255, 255), screen_w/2, screen_h/2, ALLEGRO_ALIGN_CENTRE,
		"This screen will self destruct in %i seconds", restTime);

	al_flip_display();

	al_rest(10.0);

	al_destroy_font(font36);
	al_destroy_display(display);
	
	return 0;


}//END MAIN

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>