How do I render text to the screen with OpenGL without using GLUT

I am trying to render text to the screen with OpenGL without using GLUT. How do I do this?

Core OpenGL doesn’t provide font rendering capability. Look for OpenGL extensions and libraries which offer this functionality (e.g. websearch for “opengl font rendering libraries”, tutorials, etc.)

A few links:

It may not be popular to say it, but: Setting up the full shebang and doing it all yourself with letters on textures has a couple of advantages that is rarely mentioned. You don’t have to spent time on a ‘difficult to learn’ library. You probably won’t understand the library before you’ve went through the model beneeth it: handling rectangles with painted letters upon … that is … the way you would be doing it if you had to do it all by yourself. If you’r in a learning-stage … you’ll be proficient in using textures after the session.
I made a mistake not to use a mono-font (all letters has the same width/height), so, don’t make that error. But, tapping in the letters on a high-resolution .bmp you don’t have to do much work on mapping letters to texture-coordinates when it’s been loaded. I went through my own compression-sceme (counting consecutive blacks & whites) and has written the font as a variable within the program. And I’ve spent time on making a convolution on the texture to soften it up. Slim & neat. If you already know opengl there won’t be anything that you cannot do.
I’m a bit pissed on the missing acessabillity to locale in my tools but, as a dane I only has to deal with a little handful of odd national letters. And I’m not sure that any of the libraries deals with this problem, should it arise.
Either way, it’ll take way too much time as opengl always does.

If you need support for a wide range of languages, probably the simplest solution is to use cairo to render strings to a bitmap which is then uploaded to a texture. Cairo uses Pango for text rendering, which in turn uses HarfBuzz for complex scripts (those where you can’t render each glyph in isolation, but have to take the adjacent glyphs into account in determining the shape).

Using FreeType to render individual glyphs which you position yourself works fine for Latin-based scripts (also Cyrillic and Greek). Chinese and Japanese aren’t significantly more complex but the number of glyphs is much larger (i.e. you may not be able to fit all of them inside a single 2D texture). With Korean, you have a dilemma: using pre-composed Hangul is straightforward but the number of glyphs is potentially huge, while having the application perform composition adds significant complexity. Hebrew and Arabic aren’t particularly complex by themselves, but if you have to deal with a mixture of left-to-right and right-to-left text then thing start getting awkward.

I don’t intend to steal the thread. My text-trouble belongs to C::B.
I’ve redone my text to use a mono-type. But, I intend to simplify it further by writing all constant text to texture (I expect to use button-titles and such). It’s an added complexity, but I expect my code to be crowded later on (it’s ~50000 lines, including 30000 obsoletes), so I’ve come to really enjoy simple code.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.