pygfx.materials.TextMaterial

class pygfx.materials.TextMaterial(color='#fff', *, outline_color='#000', outline_thickness=0, weight_offset=0, aa=False, **kwargs)

Bases: Material

Basic text material.

Parameters:
  • color (Color) – The color of the text.

  • outline_color (Color) – The color of the outline of the text.

  • outline_thickness (int) – A value indicating the relative width of the outline. Valid values are between 0.0 and 0.5.

  • weight_offset (int) – A value representing an offset to the font weight. Font weights are in the range 100-900, so this value should be in the same order of magnitude. Can be negative to make text thinner. Default zero.

  • aa (bool) – Whether the glyphs is anti-aliased in the shader. Default False.

  • kwargs (Any) – Additional kwargs will be passed to the material base class.

Notes

One use-case for weight_offset is to make dark text on a light background 50 units thicker, to counter the psychological effect that such text looks thinner than a light text on a dark background.

property aa

Whether the glyphs edges are anti-aliased.

Aliasing gives prettier results by producing semi-transparent fragments at the edges. Lines thinner than one physical pixel are also diminished by making them more transparent.

However, because semi-transparent fragments are introduced, artifacts may occur if certain cases. For the same reason, aa only works for the “blended” and “weighted” alpha methods.

Note that by default, pygfx already uses SSAA and/or PPAA to anti-alias the total renderered result. Text-based aa is an additional visual improvement.

property color

The color of the text.

property outline_thickness

A value indicating the relative width of the outline. Valid values are between 0.0 and 0.5. Default 0 (no outline).

property outline_color

The color of the outline of the text.

property weight_offset

A value representing an offset to the font weight. Font weights are in the range 100-900, so this value should be in the same order of magnitude. Can be negative to make text thinner. Default zero.

One use-case is to make dark text on a light background 50 units thicker, to counter the psychological effect that such text looks thinner than a light text on a dark background.