Question

What's the quickest, easiest way to draw text in standard OGL ??

Was it helpful?

Solution

Text is surprisingly involved in OpenGl
Take a look at this example from NeHe

OTHER TIPS

OpenGL does not support drawing text. You need to use some library to render text to bitmap and then you can use OpenGL to render the bitmap. Freetype2 and Pango are good cross-platform low level solutions. Game programming libraries such as ClanLib and GUI libraries such as Qt may also have their own ways for rendering text.

It depends on the framework you are working on like the one above me said. for example, SDL is multi-platform and one can draw text using a special lib inside SDL: http://gameprogrammingtutorials.blogspot.com/2010/02/sdl-tutorial-series-part-6-displaying.html

If you're using glut look at the following functions: glutStrokeString, glutBitmapString in glut documentation..

Use textures. Each character is a textured quad, and texture coordinates enclose the specific characters.

Then, you can affine using display lists, generating raster representing string at runtime, outlining, blending...

You can use a platform specific OpenGL API (i.e. wglUseFontOutlines), but I think it will be deprecated since OpenGL 3.2.

OpenGL does not support text rendering directly. You have a variety of options:

  1. Some OS bindings, such as WGL and AGL, do have limited font support (mostly they render system fonts into bitmaps for use in Open GL).
  2. The GLUT toolkit (and similar toolkits) also has some font support (bitmap and stroke).
  3. You can use a library such as FreeType (mostly a font renderer, you still may wish to use something like Pango for text layout).
  4. You can use simple textured quads (this is effectively what Quake 1 did).

Depends on what framework you are using. One common method is to render text to an offscreen buffer and use that as a texture.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top