This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine::ObjectText Class

Header: #include <UnigineObjects.h>
Inherits from: Object

The class is used to render flat text in a scene.

Usage Example#

Here is an example of creating ObjectText that will rotate following a player`s position, while the rotation of a parent stays the same, which will allow a parent node to move freely and drag a text with itself. To try it yourself, you should create a new class named TextCreator and copy .h and .cpp files into respective files of a class. Then assign a component to any desired node, which will be a parent node for the ObjectText.

TextCreator.cpp
#include "TextCreator.h"
#include <UnigineMathLib.h>

REGISTER_COMPONENT(TextCreator);

using namespace Unigine;

Unigine::ObjectTextPtr text;

void TextCreator::init() {
	// Create Object Text (created without a font or a text)
	text = Unigine::ObjectText::create();
	// Defining a text to write and a font
	text->setText(textStr.get());
	text->setFontName("font.ttf");
	text->setFontSize(100);
	text->setFontResolution(100);
	// Defining an object of a component as a parent
	text->setParent(this->getNode());
}

void TextCreator::update() {
	// Rotate a text to always look at a player
	// The pivot point will look at a player, so the it needs a little bit of tweaking
	text->worldLookAt(Game::getPlayer()->getPosition());
	// Rotate text a little bit so it shows up properly
	text->rotate(270, 0, 180);
}
TextCreator.h
#pragma once
#include <UnigineComponentSystem.h>

#include <UnigineGame.h>

class TextCreator : public Unigine::ComponentBase
{
	public:
		COMPONENT_DEFINE(TextCreator, ComponentBase)
		COMPONENT_INIT(init);
		COMPONENT_UPDATE(update);

		//Creating a parameter to define a text
		PROP_PARAM(String, textStr);
	protected:
		void init();
		void update();
};

ObjectText Class

Members


static ObjectTextPtr create ( ) #

Default constructor. Creates an empty object with no text and font set.

static ObjectTextPtr create ( const char * font_name ) #

Constructor. Creates an object with no text but with the specified font.

Arguments

  • const char * font_name - The path to the TTF font relatively to the data directory.

static ObjectTextPtr create ( const char * font_name, const char * text ) #

Constructor. Creates an object with the set font and text.

Arguments

  • const char * font_name - The path to the TTF font relatively to the data directory.
  • const char * text - The text (can be either plain or rich).

void setDepthTest ( int test ) #

Sets a value indicating if depth test should be used for the text object.

Arguments

  • int test - 1 to use depth test; otherwise, 0.

int getDepthTest ( ) const#

Returns a value indicating if the text object uses depth test.

Return value

1 if the object uses depth test; otherwise, 0.

void setFontHSpacing ( int hspacing ) #

Sets the horizontal spacing between letters (kerning value). This parameter influences the text's physical size.

Arguments

  • int hspacing - The horizontal spacing value.

int getFontHSpacing ( ) const#

Returns the horizontal spacing between letters (kerning value).

Return value

The horizontal spacing, in dots.

void setFontName ( const char * name ) #

Sets the path to the TTF font.
Notice
Names of font files for bold, italic and bold italic fonts must have the b, i and bi postfixes correspondingly. For example: myfontb.ttf, myfontbi.ttf.

Arguments

  • const char * name - The path to the TTF font relatively to the data directory.

const char * getFontName ( ) const#

Returns the path to the TTF font specified in the node.
Notice
Names of font files for bold, italic and bold italic fonts must have the b, i and bi postfixes correspondingly. For example: myfontb.ttf, myfontbi.ttf.

Return value

The path to the font relatively to the data directory, if specified; otherwise — the empty string.

void setFontOutline ( int outline ) #

Sets the outline for the text. The outline looks like the dark shadow in the right lower corner of the text and is displaced by one dot.

Arguments

  • int outline - 1 — to enable the outline; 0 — to disable.

int getFontOutline ( ) const#

Returns the flag indicating if the text outline is enabled.

Return value

1 — the outline is enabled; 0 — disabled.

void setFontResolution ( int resolution ) #

Sets the resolution of the texture into which the text will be rendered. The lower the value, the less detailed will be the text, the less video memory will be required for the texture. It doesn't influence the text's physical size.

Arguments

  • int resolution - The font resolution.

int getFontResolution ( ) const#

Returns the text resolution value.

Return value

The text resolution value.

void setFontRich ( int rich ) #

Sets the flag indicating if the rich text is enabled. When enabled, the following tags can be used for text formatting:
  • <b>text</b> specifies a bold text.
  • <i>text</i> specifies an italic text.
  • <br>text<br/> inserts a single line break.
  • <left>text</left> left-aligns the text.
  • <right>text</right> right-aligns the text.
  • <center>text</center> center-aligns the text.
  • <p align=left|right|center|justify>text</p> specifies the alignment of the text within a paragraph:
    • left - left-aligns the text
    • right - right-aligns the text
    • center - center-aligns the text
    • justify - stretches the lines so that each line has equal width (like in newspapers and magazines)
    Notice
    Text alignment requires text wrapping to be enabled: the value of the Wrap Width parameter must be greater than 0.
  • <font size=12 color=magenta face=verdana> text</font> specifies the font face, font size, and color of text.
  • <sub> text</sub> defines subscript text. Subscript text appears half a character below the normal line, and is sometimes rendered in a smaller font.
  • <sup> text</sup> defines superscript text. Superscript text appears half a character above the normal line, and is sometimes rendered in a smaller font.
Notice
<image/> and <table/> tags are not available.

Arguments

  • int rich - 1 — to enable the rich text; 0 — to disable.

int getFontRich ( ) const#

Returns the value indicating if the rich text is enabled. When enabled, tags can be used for text formatting.

Return value

1 — the rich text is enabled; 0 — disabled.

void setFontSize ( int size ) #

Sets the size of the text font. The more dots, the higher the size of the font. To match dots with a 3D space, there is a set value: 288 dots per unit. For example, if you have the Arial font with the size of 20, the physical height of the letter can be calculated as 20/288=0.0694 units.

Arguments

  • int size - The size of the text, in dots.

int getFontSize ( ) const#

Returns the text font size.

Return value

The text font size, in dots.

void setFontVSpacing ( int vspacing ) #

Sets the vertical spacing between letters (kerning value). This parameter influences the text's physical size.

Arguments

  • int vspacing - The vertical spacing value.

int getFontVSpacing ( ) const#

Returns the vertical spacing between letters (kerning value).

Return value

The vertical spacing, in dots.

void setText ( const char * text ) #

Sets the text for the node. Can be either a plain or rich text.

Arguments

  • const char * text - The text.

const char * getText ( ) const#

Returns the text set in the node.

Return value

The text.

void setTextColor ( const Math::vec4 & color ) #

Sets the color of the text.

Arguments

  • const Math::vec4 & color - The color of the text in the RGBA range.

Math::vec4 getTextColor ( ) const#

Returns the color of the text.

Return value

The text color in the RGBA range.

void setTextWrapWidth ( float width ) #

Sets text wrap width in units. The text will wrap if its physical size will be greater than the set value. If 0 is set, text wrapping is disabled.

Arguments

  • float width - Wrap width in units.

float getTextWrapWidth ( ) const#

Returns the current text wrap width in units.

Return value

Wrap width in units.

static int type ( ) #

Returns the type of the object.

Return value

Object Text type identifier.
Last update: 2022-12-14
Build: ()