OSG Text

From FlightGear wiki
Jump to navigation Jump to search

Using OSG Text, one can add text to models in FlightGear. The text can be modified runtime and can be animated using many of the animations available.

Text are scene nodes configured using XML and may appear within a model description file, like other models or the particle system.

Syntax example

For the anxious reader, here is a complete example of a text node:

<!-- Must be enclosed by a <text/> node -->
    <!-- It should have a name. Can be used for other animations -->
    <name>My first Text</name>
    <!-- Use offsets for the initial placement -->
    <!-- instead of using pitch/heading/roll offset, one may use
         axis-alignment -->
    <!-- remember: x backwards, y right and z up -->
    <!-- what type of text to draw, use on of literal, text-value or number-value -->
    <!-- A simple constant, never changing string -->
    <type type="string">literal</type>
    <text type="string">Hello, world!</text>

    <!-- The string value of a property -->
    <type type="string">text-value</type>
    <property type="string">some/property</property>
    <format type="string">%s</format> <!-- the sprintf() format to display the value -->
    <!-- A number from a property -->
    <type type="string">number-value</type>
    <property type="string">position/latitude-deg</property>
    <factor type="double">1.0</factor> <!-- optional, scale the property's value -->
    <offset type="double">0.0</offset> <!-- optional, shift the property's value -->
    <format type="string">%5.2lf</format> <!-- sprintf() format to display -->
    <truncate type="bool">false</truncate> <!-- truncate to an integer value -->
    <layout>left-to-right</layout> <!-- default -->
    <draw-text type="bool">true</draw-text> <!-- draw the text itself -->
    <draw-alignment type="bool">false</draw-alignment> <!-- draw crosshair at object center -->
    <draw-boundingbox type="bool">false</draw-boundingbox> <!-- draw a bounding box -->
    <font>led.txf</font> <!-- The font file name, relative to data/Fonts -->
    <character-size type="double">0.01</character-size> <!-- size (height) im meters -->
    <character-aspect-ratio type="double">1.0</character-aspect-ratio>
    <max-height>0.012</max-height> <!-- the maximum height of the text -->
    <max-width>0.040</max-width> <!-- the maximum width of the text -->
        <width type="int">32</width>
        <height type="int">32</height>
    <!-- chose one of the kerning types or omit for default -->
    <alignment>center-center</alignment> <!-- alignment of the text itself -->
    <!-- possible values are

The <text/> node may appear within <model/> or <PropertyList/> nodes. If you place your text directly within your model file, use <text></text> nodes. You can also put your <text> configuration into a separate file using the well known include directive:

Your model.xml file:

    <text include="HelloWorld.xml"/>

Your HelloWorld.xml:

<?xml version="1.0" encoding="UTF-8"?>

    <name>Hello World</name>
    <type type="string">literal</type>
    <text type="string">Hello, world!</text>
    <!-- etc. - you get the idea -->

Animation can be applied to text nodes like any other object. To give your text some color, use the material animation, or translate, rotate, scale or spin your text as you like.

Related content

Wiki articles

Forum topics

Readme file

Source code