Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » font size

This thread is locked; no one can reply to it. rss feed Print
font size
Recorder
Member #6,860
February 2006

Newbie question ;D

Is the only way to get a larger font size when using textout or textprintf to create a custom font? Or maybe some other output function I should use?

I don't mind using the default font but I just want it to be bigger.

ReyBrujo
Moderator
January 2001
avatar

Yes, Allegro can't use true type fonts, only bitmap-based ones. So, you need to create your own font with the size you want.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Jeff Bernard
Member #6,698
December 2005
avatar

Or you could just write a function to stretch the default font...something like this:

1// width and height are per character
2BITMAP* magnifyText(char* message, int width, int height, int r, int g, int b)
3{
4 // create bitmap to stretch_blit
5 // default font is 8x8 I believe
6 BITMAP* character = create_bitmap(8,8);
7 clear_to_color(character, makecol(255,255,255));
8 
9 // get size of message
10 int size = 0;
11 for (; message[size] != '\0'; size++);
12 
13 // create bitmap to return
14 BITMAP* text = create_bitmap(width*size, height);
15 clear_to_color(text, makecol(255,255,255));
16 
17 // stretch the message
18 for (int i = 0; i < size; i++)
19 {
20 textprintf_ex(character,font,0,0,makecol(r,g,b),-1,"%c",message<i>);
21 stretch_blit(character,text,0,0,8,8,i*width,0,width,height);
22 clear_to_color(character, makecol(255,255,255));
23 }
24 return text;
25}
26 
27// then somewhere, just...
28masked_blit(magnifyText("this is 10x10 pixels",10,10,255,255,255), ...);

This is untested code, but it looks to me like it would work. There may be some modifications to make it better...

--
I thought I was wrong once, but I was mistaken.

Recorder
Member #6,860
February 2006

Thanks. I was looking at the api and didn't any obvious 'increment here to increase font' values.

I'll try both suggestions :)

Thomas Fjellstrom
Member #476
June 2000
avatar

   // get size of message
   int size = 0;
   for (; message[size] != '\0'; size++);

How bout this instead:
int size = strlen(message);

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Jeff Bernard
Member #6,698
December 2005
avatar

Thomas Fjellstrom said:

// get size of message

int size = 0;
   for (; message[size] != '\0'; size++);

How bout this instead:
int size = strlen(message);

strlen() requires you to #include <string>. With my method, you don't need to include strings. So, if you're already using string objects, I suppose it would be better to use strlen(), however, if you don't have any other string objects I think my method would be better because then you don't have to include and entire file just for one function.

--
I thought I was wrong once, but I was mistaken.

Thomas Fjellstrom
Member #476
June 2000
avatar

actually, it requires you to include string.h, or cstring, depending on if you use C, or C++ (in that order) also, C strings are not objects, they are plain arrays of char. And its always best to use the provided standard functions.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

miran
Member #2,407
June 2002

And what's wrong with Allegro's ustrlen()?

--
sig used to be here

Go to: