SilverTiger / lwjgl3-tutorial

Tutorial for the Lightweight Java Game Library (LWJGL) 3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is the Text tutorial outdated?

otoomey opened this issue · comments

I have been using your tutorials to learn and they are very helpful, so thank you very much for writing them.

I was wondering if there exists a better way for using Fonts in LWJGL, by using the STB bindings in Build #49?

Will you be making a tutorial for NanoVG

Thanks for reading the tutorial!

Yes, you are right. It is not recommended to use AWT, and I want to remove that dependency (see issue #4). When this is done I will update the tutorial and put the AWT stuff to the appendix section. But right now I hadn't the time to fully implement Fonts with STB, but basically you have to do the following to create a bitmap with the glyphs:

stbtt_PackBegin(packContext, bitmap, imageWidth, imageHeight, 0, 1);
stbtt_PackFontRange(packContext, fontBuffer, 0, fontHeight, 32, chardata);
stbtt_PackEnd(packContext);

After that you can get the glyphs by calling stbtt_GetPackedQuad(chardata, imageWidth, imageHeight, i, xpos, ypos, quad, true); which will give you a STBTTAlignedQuad containing the vertex and texture coordinates. This demo may help you implementing it.

I will change the Font class to use STB if I have time, after that I'm thinking of doing some advanced tutorials like using NanoVG or creating audio with OpenAL.

I personally would not get rid of this tutorial because some people might want to write their own UI engine and will have this good resource no longer left to learn from.

Also the step of "Swing" could be outsourced to a different program and then have a loader that just converts the texture and a text file into a proper text Loader not requiring Swing or AWT.