OpenGL how to overlay text onto a texture

Hi All,

I use OpenGL for very basic rendering of images onto a canvas, and was just wondering what commands I can use to overlay text onto a texture? I know how to overlay points and shapes but I couldn’t find any material on overlaying text. I just need basic functionality that allows me to annotate over an image. Any help is appreciated, thanks!

If you’re using legacy OpenGL, you can use glBitmap. For modern OpenGL (or if you want anti-aliasing), you’d render textured quads (triangle pairs). FreeType can be used to rasterise glyphs to memory which can then be uploaded to a texture.

Yep it is legacy OpenGL, would you happen to have any sample code as a reference?

For rendering with glBitmap, refer to the FreeGLUT source code, specifically fg_font.c (the font data is in fg_font_data.c). FreeType can generate monochrome (1-bpp) bitmaps using FT_RENDER_MODE_MONO.

For rendering with textures, see this tutorial for the basic idea. Although ideally you’d pack multiple glyphs into one texture so that you can render entire strings with one draw call.