Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Porting from A4 to A5 - TTF fonts

This thread is locked; no one can reply to it. rss feed Print
Porting from A4 to A5 - TTF fonts
wombat
Member #12,961
June 2011

Hi all,

I started working on a game at the beginning of this year and decided to use Allegro 4 at the time.

Three days ago I decided to migrate to Allegro 5 as A5 has much better alpha support (I was having real problems getting alpha blending working with combined A4 bitmaps, fonts and primitives).

My problem is in porting the code across I had to remove my TrueType font code. For A4 I was using the FreeType library, just like A5 does (according to the Allegro docs). However the TTF text output with Allegro 5 is considerably degraded compared to what I was getting in A4.

Is anyone aware of this problem or how I can fix up the text output?

EDIT: Sorry, it appears my attachments aren't being uploaded by the forum. They're standard png format and I'm not sure why they won't upload.

Images are here:
Allegro4 TTF Font: http://imageshack.us/photo/my-images/33/allegro4ttf.png/
How the font used to render in my old A4 code (this is also very close to how it looks when using Windows font tool).

Allegro5 TTF Font: http://imageshack.us/photo/my-images/691/allegro5ttf.jpg/
How it now looks using Allegro 5's add-on for TTF fonts.

Elias
Member #358
May 2000

What if you use the same size for both?

--
"Either help out or stop whining" - Evert

wombat
Member #12,961
June 2011

Thanks for the fast reply. The fonts are being loaded in the same size.

That's what the problem is. They are both loaded as lucida sans TTf, size 12. The drawing in A4 is signficantly better (and correct size). In A5 they are clearly not being rendered as a size 12 font.

I also tried using -12 as the size (to specify size in pixels, as per the Allegro docs) which actually made things worse.

As a comparison, when used in Microsoft Word as size 12 the output is almost identical to what I had going with Allegro 4. Allegro 5's TTF output, at least for this TTF font, is way off. Allegro 5's rendering of the TTF font is not even close to correctly sized for sizes 9 - 44 (the sizes I tested at).

Elias
Member #358
May 2000

Can you provide the font and the code how you load them directly with A4+FreeType?

--
"Either help out or stop whining" - Evert

wombat
Member #12,961
June 2011

Thanks for the fast replies Elias. I'm heading off to work right now but will post the font and code when I get home tonight.

(NB: The font itself is from "C:\Windows\Fonts" but I'll make a copy of it and upload it so you have exactly what I'm using).

jmasterx
Member #11,410
October 2009

It almost sounds like A4 loads them in using PT measurements while A5 is using PX measurements.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Michał Cichoń
Member #11,736
March 2010

wombat, can you to multiply font size in Allegro5 by 1.3333 and tell us if results are the same?

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

wombat
Member #12,961
June 2011

Thanks for the replies guys.

Try using the flag ALLEGRO_TTF_MONOCHROME when loading the font in A5. Then it won't be anti-aliased. It will probably look the same then.

My A4 TTF fonts were being rendered as anti-aliased. The problem appears related to how A5 interprets font sizes rather than the rendering method itself.

jmasterx said:

It almost sounds like A4 loads them in using PT measurements while A5 is using PX measurements.

I assume the default in A5 is for font sizes to be specified in PT because the docs say use a negative value if you want PX. I tried loading as PX (negative value) but it made things even worse.

wombat, can you to multiply font size in Allegro5 by 1.3333 and tell us if results are the same?

I'm at work right now but will give it a go as soon as I get home. I'll post a screenshot of the result.

Out of interest, is there a particular reason for the rather specific 1.3333 multiplier?

EDIT: Just realised (while sitting at work thinking about it) that 1.3333 corresponds to the aspect ratio of a 4:3 display. Are Allegro fonts configured for widescreen aspect only? [Side note: I use a 30" 2560x1600 display, but I test my game in 1024x768 for compatibility reasons].

Michał Cichoń
Member #11,736
March 2010

You're feeding A5 font creation function with size expressed in pixels. Probably what you want is to express size in points, for example 12pt. See the equation:

pixel_size = point_size * resolution / 72 [1]

In case of Windows resolution is 96. Unit is DPI. As you can see you need multiply point_size by some factor and this factor is: 96 / 72 = 1.333333....

"God starts from scratch too"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

wombat
Member #12,961
June 2011

You're feeding A5 font creation function with size expressed in pixels. Probably what you want is to express size in points, for example 12pt.

Thank you, that fixed the problem!

You (and jmasterx) were right, I was using PX instead of PT. I just went and re-read the docs and realised I totally misread them the first time (and never went to recheck). I had it in my mind that the size was in points and passing negative value was for pixels. My bad.

EDIT: * Problem resolved, thanks guys *

Go to: