Why was it so hard to get font rendering working with lwjgl?

I had to mess around with so many different things to render some simple TTF text to the screen. The text displayed as a solid block of color… and the only way i managed to fix that was to pick a texture at random to bind just before rendering the text, which doesnt make any sense at all since at all since I have been binding various textures all through the map rendering code. spent several hours trawling google.

Is there any definitive info on the subject for people to get basic text working quickly and correctly?

LWJGL doesn’t have anything to do with font rendering, is probably why. It’s just pure OpenGL. You probably want to use some code somewhere from someone else rather than get bogged down rolling your own.

Cas :slight_smile:

Yeah don’t roll your own…there’s no margin in it. I have zero clue about java libraries, but if you answer a few questions somebody might be able to point you in the right direction.

  1. Fixed and/or variable width fonts?
  2. If variable do you want kerning?
  3. Fixed size(s)? And if so production or runtime?
  4. Are any of these going to smoothly scale at runtime? (signed distance field)

Those are the main ones that come to mind.

Without really knowing Your needs, You might also find help from alternative approaches.
For example quite a few games pre-render the need fonts as bitmap fonts and then use the bitmap fonts in game/app.
Hiero with libgdx https://github.com/libgdx/libgdx/wiki/Hiero

Then there is also this alternative: http://www.java-gaming.org/topics/opengl-font-without-textures/31222/view.html

I was trying to get a quick font to render so that i could observe a few variable values onscreen in real time.

perhaps an alternative would have been to open up a new window to the side of the screen and use plain java stuff to display values to that?

No, don’t do that. Use Slick-Util. Its just a few lines of code to implement font rendering, and its relatively painless. Using Java2D to draw strings in a LWJGL based program is more complex than you think, and it’s pointless.

i am using slick-util in my project. i ended up having to bind a texture just before rendering the TTF, I dont understand why that would make any difference.

You have to bind the font texture I believe. It makes sense because OpenGL is a state based machine.