17. gluttext — 2D text decorations using GLUT fonts

2D text decorations using GLUT fonts

gluttext.glutSelectFont(font=None, size=None)

Select one of the glut fonts using a font + size description.

font is one of: ‘fixed’, ‘serif’, ‘sans’ size is an int that will be rounded to the nearest available size.

The return value is a 4-character string representing one of the GLUT fonts.

gluttext.getFont(font, size)
gluttext.glutFont(font)

Return GLUT font designation for the named font.

The recognized font names are:

  • fixed: ‘9x15’, ‘8x13’,
  • times-roman: ‘tr10’, ‘tr24’
  • helvetica: ‘hv10’, ‘hv12’, ‘hv18’

If an unrecognized string is given, the default is ‘hv18’.

gluttext.glutFontHeight(font)

Return the height of the named glut font.

This supposes that the last two characters of the name hold the font height.

gluttext.glutRenderText(text, font)

Draw a text in given font at the current rasterpoint.

font should be one of the legal fonts returned by glutFont(). If text is not a string, it will be formatted to a string before drawing. After drawing, the rasterpos will have been updated!

gluttext.glutBitmapLength(font, text)

Compute the length in pixels of a text string in given font.

We use our own function to calculate the length because the builtin has a bug.

gluttext.glutDrawText(text, x, y, font='hv18', gravity='')

Draw the given text at given 2D position in window.

If adjust == ‘center’, the text will be horizontally centered on the insertion point. If adjust == ‘right’, the text will be right aligned on the point. Any other setting will align the text left. Default is to center.

Documentation

Previous topic

16. marks — OpenGL marks for annotating 3D actors.

Next topic

18. canvas — This implements an OpenGL drawing widget for painting 3D scenes.

This Page