font size
Recorder

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

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.

Jeff Bernard

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...

Recorder

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
   // get size of message
   int size = 0;
   for (; message[size] != '\0'; size++);

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

Jeff Bernard
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.

Thomas Fjellstrom

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.

miran

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

Thread #570552. Printed from Allegro.cc