Rendering Text in OpenGL

Rendering text is very difficult in software. (fonts, languages and layout can be quite different, so it depends.)

that tutorial creates a texture for each letter(glyph) of the font. It then just loops through a string of letters, and binds the texture, and sends down the offset position, and draws it.

That's not a good way of doing it in practice, since it requires A LOT of unnecessary texture changes and draw calls, and only outputs a single line of text, but it's just for learning the font concepts. The concepts are roughly the same in practice. Obviously, you'd be better off with a texture atlas and instancing (and a uniform/UBO struct array).

The layout is the big thing depends on what you're doing: a 2D overlay, 3D translated, font sizes(rasterized), single line, paragraph, embedded, dynamic text, static text, etc. You have to layout the text first (in the tutorial, he just did a single line) before you can draw it.

Look into signed distance fields. You convert a bitmap/pixels of a font to SDF format, and do the texture atlas/instancing thing. It works well for pretty much anything, performs pretty well, and the shader is pretty simple. You still have to do layout first.

Yea, it seems confusing at first, but text layout/render is not as easy as one would assume, but it's not bad once you understand it. It can be quite easy, actually. Take a look at [https://github.com/rougier/freetype-gl](freetype-gl) if you want some examples to look at. It's a bit more convoluted, and requires a bit of dependencies, than what you really need, but running the demos and looking at the code overall can be educational.

/r/opengl Thread