Best way to create/load and render fonts?

I am using LWJGL 3.1.5 with that OpenGL, STB
I wonder how to render fonts (also strings) in places where the string will change.

I tried searching but I’ve only found tutorials/snippets for C++ :-
Thankies :slight_smile:

I’ve always used BitMap fonts to do this.
Basically, I used awt.Graphics2D to draw every character I need to an image file while storing the pixel coordinates in a text file (you also just could use a freely available bitmap font program). I then just have to load this file and every time I want to render a character, I look up its position in the texture, bind this part and render it.

(If you want, I could post my files here, but they are quite large and currently undocumented.)

You can render fonts completely dynamically at runtime with LWJGL3. Basically STB is a wonderful library that provides two ways to render fonts - drawing the geometry directly (EasyFont) and generating bitmap textures and providing texture coords (Truetype). I’d recommend the latter as being slightly more complicated but better and far easier to work into an existing render pipeline.

Check out the LWJGL demos (which are also wonderful and kept remarkably up to date) for examples of both: https://github.com/LWJGL/lwjgl3/tree/master/modules/core/src/test/java/org/lwjgl/demo/stb
EasyFont.java does the geometry base rendering.
Truetype.java does the bitmap based rendering.
FontDemo is the superclass for both demos which you’ll probably have to refer to.

Here is a nice Tool to create Font Bitmaps

Codehead’s Bitmap Font Generator
http://www.codehead.co.uk/cbfg/