Fonts in LWJGL

Hi all,

I’ve been using a custom bitmap font in my games for a while now, which suited great because the UI was scaled-up for that ‘retro’ low-resolution look.

However, now that I’m doing a higher resolution game I’m looking to use a normal font - something clean like Open Sans (TT), but I’m totally stumped about font support in an OpenGL (LWJGL) environment.

I tried using the built-in TrueType class, but it seems to only allow loading fonts that are installed on the target system? Not from a location in the runtime path?

I’m ideally looking for a nice clean font for my UI, tooltips and such, that can be anti-aliased, but doesn’t have a massive performance hit if I need to output a paragraph or two of text.

Any advice would be greatly appreciated!

Thanks,
PixelPrime

Here’s some code I wrote about a year ago: https://github.com/CopyableCougar4/Font-Rendering/blob/master/src/com/digiturtle/ui/GLFont.java

There are 3 or 4 classes in that repo, but it’s pretty much self contained (although it uses immediate mode rendering so you may want to update that).

That’s really helpful, thank you!

[quote=“pixelprime,post:1,topic:54739”]
Not sure what you mean. You can load a .ttf file into a ByteBuffer any way you like, then use it with the TrueType class. This demo might help.

Thanks for your help! :slight_smile:

RE: CopyableCouger

I implemented your classes without any trouble, but I’m wondering whether or not you have any known rendering bugs?

I’ve tried this using a variety of fonts - but let’s say for argument’s sake I’m going for something clean, like OpenSans, this is the sort of output I’m getting:

It’s a bit weird - you can see some speckles here and there which I can only guess are something to do with the way the text glyphs are rendered? I’ve clamped the X,Y display position of text to whole numbers to ensure it’s not an aliasing issue.

I get this result with pretty much any font I use - so I just want to check if I need to do any mode switching or change texture clamp settings or anything first?

Thanks buddy!
Pixel

Change

positionY += rowHeight + 10;

to

positionY += rowHeight + metrics.getAscent() + metrics.getDescent() + 10;

and see if that helps.

Sadly no avail on the fix :frowning: But I appreciate you taking the time to offer a suggestion. I’ll have a play about with it at some point and see if I can figure it out.

Thanks :slight_smile: