Public Member Functions | Protected Member Functions | List of all members
Renderable3DTextComponentInstance Class Reference

#include <renderable3dtextcomponent.h>

Public Member Functions

 Renderable3DTextComponentInstance (EntityInstance &entity, Component &resource)
virtual bool init (utility::ErrorState &errorState) override
void normalizeText (bool enable)
bool isNormalized () const
bool computeNormalizationFactor (const std::string &referenceText)
virtual RenderableGlyphgetRenderableGlyph (uint index, float scale, utility::ErrorState &error) const override
- Public Member Functions inherited from RenderableTextComponentInstance
 RenderableTextComponentInstance (EntityInstance &entity, Component &resource)
const FontInstancegetFont () const
bool setText (const std::string &text, utility::ErrorState &error)
void setColor (const glm::vec3 &color)
bool setText (int lineIndex, const std::string &text, utility::ErrorState &error)
bool addLine (const std::string &text, utility::ErrorState &error)
void setLineIndex (int index)
const std::string & getText ()
const std::string & getText (int index)
void resize (int lines)
int getCount () const
void clear ()
const math::RectgetBoundingBox () const
const math::RectgetBoundingBox (int index)
const MaterialInstancegetMaterialInstance () const
MaterialInstancegetMaterialInstance ()
float getDPIScale () const
- Public Member Functions inherited from RenderableComponentInstance
 RenderableComponentInstance (EntityInstance &entity, Component &resource)
void draw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix)
void setVisible (bool visible)
bool isVisible () const
virtual bool isSupported (nap::CameraComponentInstance &camera) const
- Public Member Functions inherited from ComponentInstance
 ComponentInstance (EntityInstance &entity, Component &resource)
virtual void update (double deltaTime)
nap::EntityInstancegetEntityInstance () const
nap::ComponentgetComponent () const
template<typename T >
T * getComponent () const
- Public Member Functions inherited from Object
 Object ()
virtual ~Object ()
virtual void onDestroy ()
 Object (Object &)=delete
Objectoperator= (const Object &)=delete
 Object (Object &&)=delete
Objectoperator= (Object &&)=delete

Protected Member Functions

virtual void onDraw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix) override
- Protected Member Functions inherited from RenderableTextComponentInstance
void draw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix, const glm::mat4 &modelMatrix)
bool hasTransform () const
const nap::TransformComponentInstancegetTransform () const
virtual bool setup (float scale, utility::ErrorState &errorState)

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
- Protected Attributes inherited from RenderableTextComponentInstance
FontInstancemFont = nullptr
 Pointer to the font, set on initialization. More...
RenderServicemRenderService = nullptr
 Pointer to the Renderer. More...


Runtime version of the Renderable3DTextComponent. This component allows you to render flat text at a specific location in the world.

3D text can only be rendered using the render service, similar to how 3D meshes are rendered. The text can be transformed, scaled and rotated. It's best to render 3D text using a perspective camera. The font size directly influences the size of the text unless normalization is turned on. When normalization is turned on the text is rendered centered on the origin with -0.5-0,5 bounds.

It is possible to cache multiple lines at once, where each line can be selected and drawn individually inside a render loop. This is useful when you want the same component to render multiple lines of text, removing the need to declare a component for each individual line. You cannot update or add a line of text when rendering a frame: inside the render loop. Only update or add new lines of text on update. You can however change the position and line of text to draw inside the render loop.

Inheritance diagram for Renderable3DTextComponentInstance:
Collaboration diagram for Renderable3DTextComponentInstance:

Constructor & Destructor Documentation

◆ Renderable3DTextComponentInstance()

Member Function Documentation

◆ computeNormalizationFactor()

bool computeNormalizationFactor ( const std::string &  referenceText)

Calculates normalization factor based on the given reference text. This is called automatically on initialization but can be changed at runtime. Caching this value ensures that at runtime the size of the text doesn't change when normalization is turned on.

referenceTexttext used to calculate the normalization factor
if the bounds updated correctly based on the reference text

◆ getRenderableGlyph()

virtual RenderableGlyph* getRenderableGlyph ( uint  index,
float  scale,
utility::ErrorState error 
) const

Creates a Renderable2DMipMapGlyph using the given character index and scale.

indexthe index to create the render-able glyph for.
scalethe render-able glyph scaling factor.
errorcontains the error if the glyph representation could not be created.
the Renderable2DMipMapGlyph glyph for the given character index.

Implements RenderableTextComponentInstance.

◆ init()

virtual bool init ( utility::ErrorState errorState)

Initialize Renderable3DTextComponentInstance based on the Renderable3DTextComponent resource

errorStateshould hold the error message when initialization fails
if the Renderable3DTextComponentInstance is initialized successfully

Reimplemented from RenderableTextComponentInstance.

◆ isNormalized()

bool isNormalized ( ) const
if the text is drawn normalized, normalized text is 1 unit long and centered around the origin

◆ normalizeText()

void normalizeText ( bool  enable)

Enables or disables normalization. Normalized text is centered around the origin with approx -0.5 / 0.5 bounds The normalization factor is based on reference text which can be updated by calling: computeNormalizationFactor() Calling computeNormalizationFactor() ensures that the size of the letters don't change size at runtime.

enabledisable or enable normalization

◆ onDraw()

virtual void onDraw ( IRenderTarget renderTarget,
VkCommandBuffer  commandBuffer,
const glm::mat4 &  viewMatrix,
const glm::mat4 &  projectionMatrix 

Draws the text to the currently active render target using the render service. The size of the text is directly related to the size of the font. This function is called by the render service when text is rendered with a user defined camera. In that case the viewMatrix is the world space camera location and the the projection matrix is defined by the camera type. This can be orthographic or perspective. It is recommended to only use a perspective camera when rendering text in 3D. The TransformComponent of the parent entity is used to place the text and is therefore required.

renderTargettarget to render to
commandBuffercurrent command buffer
viewMatrixthe camera world space location
projectionMatrixthe camera projection matrix, orthographic or perspective

Implements RenderableComponentInstance.