How wan i display text in an OpenGL program?
I’m using MinGW, but the tutorials on the web are using libraries that are specific for Windows development (take HDc as parameter).
How wan i display text in an OpenGL program? I’m using MinGW, but the
Share
OpenGL doesn’t have any font rendering built into it. On most platforms, you can invoke platform-specific calls to render text on top of your OpenGL display (or around it), which is probably what those tutorials are doing. If you want the text to be part of your OpenGL scene, you need to roll your own.
A common approach is to use an existing font rendering library (say, freetype), render your text to a bitmap, and use that as a texture.
If you need to render a lot of text, you may be better off converting individual glyphs into textures; rendering one glyph then takes one quad (and you can use the usual optimizations to make it render fast).
Instead of TTF / OTF fonts, you can of course also just use pre-rendered bitmaps; this removes the need for a font rendering library at runtime, but it won’t allow you to dynamically change the font size (although you can of course render stretched instances of your text).
Another option: libcairo seems to have an (experimental) OpenGL backend, so maybe that’s worth checking out.