Re: TextRenderer and memory issues

Posted by farrellf on
URL: https://forum.jogamp.org/TextRenderer-and-memory-issues-tp4041129p4041134.html

Sounds like the memory leak I experienced a while ago:
http://forum.jogamp.org/TextRenderer-memory-leak-td4039967.html

I didn't find an easy way to fix TextRenderer, and like you also found out, the graph API's text render has a bunch of problems that made it unusable for me.

I ended up writing my own 2D text rendering code. It's very primitive (only 2D, only 3 font sizes, only black text, only horizontal or vertical text, etc.) but works perfectly for my use cases.

So unfortunately, like Julien said, you'll have to use another library (or DIY it.)

My code isn't meant to be a library, but you can probably rip out the parts you need and work it into your codebase. My code works with OpenGL 3.2+ and OpenGL ES 3.2.

Here is what my text rendering looks like:
https://youtu.be/FqfgBnCdrTo?t=30

Functions for drawing text and getting the text width (in pixels) start here:
https://github.com/farrellf/TelemetryViewer/blob/master/Telemetry%20Viewer/src/OpenGL.java#L486

This function updates the texture atlases. Uncomment the lines at the end to see what the atlas looks like:
https://github.com/farrellf/TelemetryViewer/blob/master/Telemetry%20Viewer/src/OpenGL.java#L822

Info about the typical text height (in pixels) is around here:
https://github.com/farrellf/TelemetryViewer/blob/master/Telemetry%20Viewer/src/OpenGL.java#L1658

The shader compilation stuff is here (among all of the other code not relevant to text rendering...)
https://github.com/farrellf/TelemetryViewer/blob/master/Telemetry%20Viewer/src/OpenGL.java#L1687

That whole file (OpenGL.java) is my mini abstraction layer for OpenGL. Good luck!

-Farrell