### Navigation

- index
- modules |
- next |
- previous |
- pyFormex 0.9.1 documentation >
- pyFormex reference manual >

# 24. `gluttext` — 2D text decorations using GLUT fonts

This module provides the basic functions for using the GLUT library in the rendering of text on an OpenGL canvas.

`Classes defined in module gluttext`

`Functions defined in module gluttext`

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

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

  - font: ‘fixed’, ‘serif’ or ‘sans’
  - size: 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.``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, gravity='')

  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='', spacing=1.0)

  Draw a text at given 2D position in window.

  - text: a simple string, a multiline string or a list of strings. If it is a string, it will be splitted on the occurrence of ‘n’ characters.
  - x,y: insertion position on the canvas
  - gravity: a string that determines the adjusting of the text with respect to the insert position. It can be a combination of one of the characters ‘N or ‘S’ to specify the vertical positon, and ‘W’ or ‘E’ for the horizontal. The default(empty) string will center the text.

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex 0.9.1 documentation >
- pyFormex reference manual >