PDA

View Full Version : Text drawing in GL 4.3



sam_thedancer
06-19-2013, 07:02 AM
Greetings:
What's the best way to draw text in GL 4.3 core? I searched the forum but couldn't find a good answer. The wiki below seems a bit dated too.
http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_01

I don't need anything fancy - basically, need to label stuff and output messages. Something almost as convenient as glutStrokeCharacter would be great.

Thanks for suggestions,
Sam

GClements
06-19-2013, 08:01 AM
What's the best way to draw text in GL 4.3 core?
For efficiency, you want to use as few draw calls as possible, i.e. one per line or block of text rather than one per glyph. The easiest way is to just render it as a mesh, i.e. two triangles for each glyph.

You can reduce the memory required by using a geometry shader which takes GL_POINTS with the character code and position as attributes and generates a pair of triangles using metrics stored in a texture.

If you're using a monospaced font, you can use gl_VertexID to generate the X offset. For a proportional font, each glyph has to be placed explicitly (the concurrent nature of GLSL means that you can't calculate the offset based upon that for the previous character).

sam_thedancer
06-19-2013, 08:06 AM
Thanks, GClements.
But I was wondering if there's library or such that I can just plug in. I really don't want to spend time making glyphs myself as the text is just incidental to my program.

tonyo_au
06-19-2013, 07:09 PM
If you just want something quick try this
http://github.prideout.net/strings-inside-vertex-buffers/