7 Replies - 462 Views - Last Post: 15 January 2013 - 03:00 PM Rate Topic: -----

#1 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Allegro al_draw_textf

Posted 15 January 2013 - 11:28 AM

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


Is This A Good Question/Topic? 0
  • +

Replies To: Allegro al_draw_textf

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Allegro al_draw_textf

Posted 15 January 2013 - 01:07 PM

Are you sure that '%i' is the correct format specifier for integer output? How about '%d'?
Was This Post Helpful? 1
  • +
  • -

#3 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: Allegro al_draw_textf

Posted 15 January 2013 - 01:23 PM

Yes, I tried %d.. same result. This is the strangest problem ever. Thank you for trying though!
Was This Post Helpful? 0
  • +
  • -

#4 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Allegro al_draw_textf

Posted 15 January 2013 - 02:41 PM

View Postsynlight, on 15 January 2013 - 08:23 PM, said:

Yes, I tried %d.. same result. This is the strangest problem ever. Thank you for trying though!


I compiled the code in MSVC++ 2010 (using Allegro 5.0.8 and linking 'allegro-5.0.8-monolith-md-debug.lib'), downloaded the font file "Orange Juice.tff" and didn't have the same problem. The code seems to work as intended.

Screenshot.
Posted Image

Seems that it could be something wrong with your Allegro setup, perhaps.

This post has been edited by Aphex19: 15 January 2013 - 02:43 PM

Was This Post Helpful? 1
  • +
  • -

#5 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: Allegro al_draw_textf

Posted 15 January 2013 - 02:46 PM

What the hell.
I'm using MSC++E

Allegro 5.0.8, the monolith build. Everything is the same as yours.

Here is my screenshot:


Posted Image


View PostAphex19, on 15 January 2013 - 04:41 PM, said:

View Postsynlight, on 15 January 2013 - 08:23 PM, said:

Yes, I tried %d.. same result. This is the strangest problem ever. Thank you for trying though!


I compiled the code in MSVC++ (using Allegro 5.0.8 and linking 'allegro-5.0.8-monolith-md-debug.lib'), downloaded the font file "Orange Juice.tff" and don't have the same problem. The code seems to work as intended.

Screenshot.
Posted Image

Was This Post Helpful? 0
  • +
  • -

#6 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Allegro al_draw_textf

Posted 15 January 2013 - 02:54 PM

It's a long shot, but could it be the font you're using? The one I used I found here.
Was This Post Helpful? 2
  • +
  • -

#7 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: Allegro al_draw_textf

Posted 15 January 2013 - 02:54 PM

Oh FFS. The tff file I was using has no numerals in it.

Thank you so much for trying to help. Now I feel like an idiot. I'm sorry I wasted your time. :sarcasm:
Was This Post Helpful? 0
  • +
  • -

#8 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Allegro al_draw_textf

Posted 15 January 2013 - 03:00 PM

No problem. Glad to help.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1