SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLText Class Reference

SLText creates a mesh using a textured font from SLTexFont. More...

#include <SLText.h>

Inheritance diagram for SLText:
[legend]

Public Member Functions

 SLText (SLstring text, SLTexFont *font, SLCol4f txtCol=SLCol4f::WHITE, SLfloat maxWidth=0.0f, SLfloat lineHeightFactor=1.3f)
 Construct a new SLText::SLText object. More...
 
 ~SLText ()
 
void drawText (SLSceneView *sv)
 
void statsRec (SLNodeStats &stats) override
 
SLAABBoxupdateAABBRec (SLbool updateAlsoAABBinOS) override
 
SLbool hitRec (SLRay *ray) override
 
void drawMesh (SLSceneView *sv) override
 Draws the single mesh. More...
 
void preShade (SLRay *ray)
 
SLstring text ()
 
SLCol4f color ()
 
SLVec2f size ()
 
SLfloat fontHeightPX ()
 
SLint length ()
 
- Public Member Functions inherited from SLNode
 SLNode (const SLstring &name="Node")
 Construct a new SLNode::SLNode object. More...
 
 SLNode (SLMesh *mesh, const SLstring &name="Node")
 
 SLNode (SLMesh *mesh, const SLVec3f &translation, const SLstring &name)
 
 ~SLNode () override
 
virtual void cull3DRec (SLSceneView *sv)
 
virtual void cullChildren3D (SLSceneView *sv)
 Initializer function to call SLNode::cull3DRec recursively. More...
 
virtual void cull2DRec (SLSceneView *sv)
 
virtual SLNodecopyRec ()
 
virtual void dumpRec ()
 
void setDrawBitsRec (SLuint bit, SLbool state)
 
void setPrimitiveTypeRec (SLGLPrimitiveType primitiveType)
 
virtual void addMesh (SLMesh *mesh)
 
bool removeMesh ()
 Returns true if a mesh was assigned and set it to nullptr. More...
 
bool removeMesh (SLMesh *mesh)
 Returns true if the passed mesh was assigned and sets it to nullptr. More...
 
SLint numChildren ()
 
void addChild (SLNode *child)
 
bool insertChild (SLNode *insertC, SLNode *afterC)
 
void deleteChildren ()
 
bool deleteChild ()
 
bool deleteChild (SLNode *child)
 
bool deleteChild (const SLstring &name)
 
bool removeChild (SLNode *child)
 remove child from vector of children. Removes false if not found, else true. More...
 
template<typename T >
T * find (const SLstring &name="", SLbool findRecursive=true)
 
template<typename T >
T * findChild (const SLstring &name="", SLbool findRecursive=true)
 
template<typename T >
deque< T * > findChildren (const SLstring &name="", SLbool findRecursive=true, SLbool canContain=false)
 
deque< SLNode * > findChildren (const SLMesh *mesh, SLbool findRecursive=true)
 
deque< SLNode * > findChildren (SLuint drawbit, SLbool findRecursive=true)
 
SLVec3f translationOS () const
 
SLVec3f forwardOS () const
 
SLVec3f rightOS () const
 
SLVec3f upOS () const
 
SLVec3f axisXOS () const
 
SLVec3f axisYOS () const
 
SLVec3f axisZOS () const
 
SLVec3f translationWS () const
 
SLVec3f forwardWS () const
 
SLVec3f rightWS () const
 
SLVec3f upWS () const
 
SLVec3f axisXWS () const
 
SLVec3f axisYWS () const
 
SLVec3f axisZWS () const
 
void translation (const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
 
void translation (SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_parent)
 
void rotation (const SLQuat4f &rot, SLTransformSpace relativeTo=TS_parent)
 
void rotation (SLfloat angleDeg, const SLVec3f &axis, SLTransformSpace relativeTo=TS_parent)
 
void scaling (SLfloat s)
 
void scaling (SLfloat x, SLfloat y, SLfloat z)
 
void scaling (const SLVec3f &scaling)
 
void lookAt (SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
 
void lookAt (const SLVec3f &target, const SLVec3f &up=SLVec3f::AXISY, SLTransformSpace relativeTo=TS_world)
 
void translate (const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
 
void translate (SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_object)
 
void rotate (const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
 
void rotate (SLfloat angleDeg, const SLVec3f &axis, SLTransformSpace relativeTo=TS_object)
 
void rotate (SLfloat angleDeg, SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_object)
 
void rotateAround (const SLVec3f &point, SLVec3f &axis, SLfloat angleDeg, SLTransformSpace relativeTo=TS_world)
 
void scale (SLfloat s)
 
void scale (SLfloat x, SLfloat y, SLfloat z)
 
void scale (const SLVec3f &scale)
 
void scaleToCenter (SLfloat maxDim)
 
void setInitialState ()
 
void resetToInitialState ()
 
void parent (SLNode *p)
 
void entityID (SLint entityID)
 
void om (const SLMat4f &mat)
 
void animation (SLAnimation *a)
 
void castsShadows (SLbool castsShadows)
 
virtual void needUpdate ()
 
void needWMUpdate ()
 
void needAABBUpdate ()
 
void isSelected (bool isSelected)
 
void minLodCoverage (SLfloat minLodCoverage)
 
void levelForSM (SLubyte lfsm)
 
void onUpdateCB (function< void()> callbackFunc)
 
SLNodeparent ()
 
SLint depth () const
 
SLint entityID () const
 
const SLMat4fom ()
 
const SLMat4finitialOM ()
 
const SLMat4fupdateAndGetWM () const
 
const SLMat4fupdateAndGetWMI () const
 
SLDrawBitsdrawBits ()
 
SLbool drawBit (SLuint bit)
 
SLAABBoxaabb ()
 
SLAnimationanimation ()
 
SLbool castsShadows ()
 
SLMeshmesh ()
 
SLVNodechildren ()
 
const SLAnimSkeletonskeleton ()
 Returns the first skeleton found in the meshes. More...
 
void updateRec ()
 
virtual void doUpdate ()
 
bool updateMeshSkins (bool forceCPUSkinning, const std::function< void(SLMesh *)> &cbInformNodes)
 Update all skinned meshes recursively. More...
 
void updateMeshAccelStructs ()
 
void updateMeshMat (std::function< void(SLMaterial *m)> setMat, bool recursive)
 Updates the mesh material recursively with a material lambda. More...
 
void setMeshMat (SLMaterial *mat, bool recursive)
 Set the mesh material recursively. More...
 
bool isSelected ()
 
SLfloat minLodCoverage ()
 
SLubyte levelForSM ()
 
- Public Member Functions inherited from SLObject
 SLObject (const SLstring &Name="", const SLstring &url="")
 
virtual ~SLObject ()
 
void name (const SLstring &Name)
 
void url (const SLstring &url)
 
const SLstringname () const
 
const SLstringurl () const
 
- Public Member Functions inherited from SLEventHandler
 SLEventHandler ()
 
virtual ~SLEventHandler ()
 
virtual SLbool onMouseDown (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseUp (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseMove (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onDoubleClick (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseWheel (const SLint delta, const SLKey mod)
 
virtual SLbool onTouch2Down (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch2Move (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch2Up (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch3Down (const SLint x1, const SLint y1)
 
virtual SLbool onTouch3Move (const SLint x1, const SLint y1)
 
virtual SLbool onTouch3Up (const SLint x1, const SLint y1)
 
virtual SLbool onKeyPress (const SLKey key, const SLKey mod)
 
virtual SLbool onKeyRelease (const SLKey key, const SLKey mod)
 
virtual SLbool onRotationPYR (const SLfloat pitchRAD, const SLfloat yawRAD, const SLfloat rollRAD)
 
void mouseRotationFactor (SLfloat rf)
 
SLfloat mouseRotationFactor ()
 

Protected Attributes

SLstring _text
 Text of the button. More...
 
SLTexFont_font
 Font pointer of the preloaded font. More...
 
SLCol4f _color
 RGBA-Color of the text. More...
 
SLfloat _maxW
 Max. width in pix. for wrapped text. More...
 
SLfloat _lineH
 Line height factor for wrapped text. More...
 
SLGLVertexArray _vao
 Vertex array for rendering. More...
 
- Protected Attributes inherited from SLNode
SLNode_parent
 pointer to the parent node More...
 
SLVNode _children
 vector of children nodes More...
 
SLMesh_mesh
 pointer to a single mesh More...
 
SLint _depth
 depth of the node in a scene tree More...
 
SLint _entityID
 ID in the SLVEntity graph for Data Oriented Design. More...
 
SLMat4f _om
 object matrix for local transforms More...
 
SLMat4f _initialOM
 the initial om state More...
 
SLMat4f _wm
 world matrix for world transform More...
 
SLMat4f _wmI
 inverse world matrix More...
 
SLbool _isWMUpToDate
 is the WM of this node still valid More...
 
SLbool _isWMIUpToDate
 is the inverse WM of this node still valid More...
 
SLbool _isAABBUpToDate
 is the saved aabb still valid More...
 
bool _castsShadows
 flag if meshes of node should cast shadows More...
 
bool _isSelected
 flag if node and one or more of its meshes are selected More...
 
SLDrawBits _drawBits
 node level drawing flags More...
 
SLAABBox _aabb
 axis aligned bounding box More...
 
SLAnimation_animation
 animation of the node More...
 
SLfloat _minLodCoverage
 Min. LOD coverage for visibility (0.0 < _minLodCoverage < 1.0) More...
 
SLubyte _levelForSM
 Level of LOD to use for shadow mapping (0 = the visible one will be drawn) More...
 
function< void()> _onUpdateCB
 Optional lambda callback once per update. More...
 
- Protected Attributes inherited from SLObject
SLstring _name
 name of an object More...
 
SLstring _url
 uniform resource locator More...
 
- Protected Attributes inherited from SLEventHandler
SLfloat _mouseRotationFactor
 Mouse rotation sensibility. More...
 
SLfloat _keyboardDeltaPos
 Delta dist. for keyboard translation. More...
 

Additional Inherited Members

- Static Public Attributes inherited from SLNode
static SLuint numWMUpdates = 0
 NO. of calls to updateWMRec per frame. More...
 
static unsigned int instanceIndex = 0
 ??? More...
 

Detailed Description

SLText creates a mesh using a textured font from SLTexFont.

The text is passed as standard string that can contain line breaks (\n). Line breaks are only inserted if a maxWidth is defined. If the lineHeightFactor is 1.0 the minimal line spacing is used.

Definition at line 29 of file SLText.h.

Constructor & Destructor Documentation

◆ SLText()

SLText::SLText ( SLstring  text,
SLTexFont font,
SLCol4f  color = SLCol4f::WHITE,
SLfloat  maxWidth = 0.0f,
SLfloat  lineHeightFactor = 1.3f 
)

Construct a new SLText::SLText object.

Remarks
It is important that during instantiation NO OpenGL functions (gl*) get called because this constructor will be most probably called in a parallel thread from within an SLScene::registerAssetsToLoad or SLScene::assemble function. All objects that get rendered have to do their OpenGL initialization when they are used the first time during rendering in the main thread.
Parameters
textText to be rendered
fontSLTexTont to be used
colorColor for font
maxWidthMax. line width in pixels
lineHeightFactorLine hight factor >= 1.0

Definition at line 28 of file SLText.cpp.

33  : SLNode("Text")
34 {
35  assert(font);
36  _font = font;
37  _text = text;
38  _color = color;
39  _maxW = maxWidth;
40  _lineH = lineHeightFactor;
41 }
SLNode(const SLstring &name="Node")
Construct a new SLNode::SLNode object.
Definition: SLNode.cpp:40
SLstring text()
Definition: SLText.h:48
SLfloat _lineH
Line height factor for wrapped text.
Definition: SLText.h:61
SLstring _text
Text of the button.
Definition: SLText.h:57
SLCol4f color()
Definition: SLText.h:49
SLTexFont * _font
Font pointer of the preloaded font.
Definition: SLText.h:58
SLfloat _maxW
Max. width in pix. for wrapped text.
Definition: SLText.h:60
SLCol4f _color
RGBA-Color of the text.
Definition: SLText.h:59

◆ ~SLText()

SLText::~SLText ( )
inline

Definition at line 38 of file SLText.h.

38 { ; }

Member Function Documentation

◆ color()

SLCol4f SLText::color ( )
inline

Definition at line 49 of file SLText.h.

49 { return _color; }

◆ drawMesh()

void SLText::drawMesh ( SLSceneView sv)
inlineoverridevirtual

Draws the single mesh.

Inserts a mesh pointer in the mesh pointer vector after the specified afterM pointer.

Reimplemented from SLNode.

Definition at line 44 of file SLText.h.

44 { drawText(sv); };
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void drawText(SLSceneView *sv)
Definition: SLText.cpp:46

◆ drawText()

void SLText::drawText ( SLSceneView sv)

SLText::shapeDraw draws the text buffer objects

Definition at line 46 of file SLText.cpp.

47 {
48  if (_drawBits.get(SL_DB_HIDDEN) || !SLGLState::instance()->blend()) return;
49 
50  // create buffer object for text once
51  if (!_vao.vaoID())
52  {
55  _font->magFiler(GL_LINEAR);
56  }
57  // Enable & build font texture with active OpenGL context
58  _font->bindActive();
59 
60  // Setup shader
62  SLGLState* state = SLGLState::instance();
63  sp->useProgram();
64  sp->uniformMatrix4fv("u_mMatrix", 1, (const SLfloat*)&updateAndGetWM());
65  sp->uniformMatrix4fv("u_vMatrix", 1, (const SLfloat*)&state->viewMatrix);
66  sp->uniformMatrix4fv("u_pMatrix", 1, (const SLfloat*)&state->projectionMatrix);
67  sp->uniform4fv("u_textColor", 1, (float*)&_color);
68  sp->uniform1i("u_matTexture0", 0);
69 
70  _vao.drawElementsAs(PT_triangles, (SLuint)_text.length() * 2 * 3);
71 }
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
#define SL_DB_HIDDEN
Flags an object as hidden.
Definition: SLDrawBits.h:20
@ PT_triangles
Definition: SLGLEnums.h:35
#define SL_ANISOTROPY_MAX
Definition: SLGLTexture.h:34
SLbool get(SLuint bit)
Returns the specified bit.
Definition: SLDrawBits.h:69
Encapsulation of an OpenGL shader program object.
Definition: SLGLProgram.h:56
SLint uniformMatrix4fv(const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const
Passes a 4x4 float matrix values py pointer to the uniform variable "name".
SLint uniform4fv(const SLchar *name, SLsizei count, const SLfloat *value) const
Passes 4 float values py pointer to the uniform variable "name".
void useProgram()
SLint uniform1i(const SLchar *name, SLint v0) const
Passes the int values v0 to the uniform variable "name".
Singleton class holding all OpenGL states.
Definition: SLGLState.h:71
static SLGLState * instance()
Public static instance getter for singleton pattern.
Definition: SLGLState.h:74
SLMat4f viewMatrix
matrix for the active cameras view transform
Definition: SLGLState.h:91
void blend(SLbool state)
Definition: SLGLState.cpp:236
SLMat4f projectionMatrix
matrix for projection transform
Definition: SLGLState.h:90
void minFiler(SLint minF)
Definition: SLGLTexture.h:203
void magFiler(SLint magF)
Definition: SLGLTexture.h:204
void bindActive(SLuint texUnit=0)
void drawElementsAs(SLGLPrimitiveType primitiveType, SLuint numIndexes=0, SLuint indexOffsetBytes=0)
Draws the VAO by element indices with a primitive type.
SLuint vaoID() const
Returns either the VAO id or the VBO id.
SLDrawBits _drawBits
node level drawing flags
Definition: SLNode.h:359
const SLMat4f & updateAndGetWM() const
Definition: SLNode.cpp:703
void buildTextBuffers(SLGLVertexArray &vao, const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeight=1.5f)
Definition: SLTexFont.cpp:345
SLGLProgram * fontTexProgram()
Definition: SLTexFont.h:56
SLGLVertexArray _vao
Vertex array for rendering.
Definition: SLText.h:62

◆ fontHeightPX()

SLfloat SLText::fontHeightPX ( )
inline

Definition at line 53 of file SLText.h.

53 { return (SLfloat)_font->charsHeight; }
SLint charsHeight
Definition: SLTexFont.h:69

◆ hitRec()

SLbool SLText::hitRec ( SLRay ray)
inlineoverridevirtual

Intersects the nodes meshes with the given ray. The intersection test is only done if the AABB is intersected. The ray-mesh intersection is done in the nodes object space. The rays origin and direction is therefore transformed into the object space.

Reimplemented from SLNode.

Definition at line 43 of file SLText.h.

43 { return false; }

◆ length()

SLint SLText::length ( )
inline

Definition at line 54 of file SLText.h.

54 { return (SLint)_text.length(); }
int SLint
Definition: SL.h:170

◆ preShade()

void SLText::preShade ( SLRay ray)
inline

Definition at line 45 of file SLText.h.

45 { ; }

◆ size()

SLVec2f SLText::size ( )
inline

Definition at line 50 of file SLText.h.

50  { return _font->calcTextSize(_text,
51  _maxW,
52  _lineH); }
SLVec2f calcTextSize(const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeightFactor=1.5f)
Definition: SLTexFont.cpp:243

◆ statsRec()

void SLText::statsRec ( SLNodeStats stats)
overridevirtual

SLText::statsRec updates the statistics.

Reimplemented from SLNode.

Definition at line 76 of file SLText.cpp.

77 {
78  stats.numBytes += (SLuint)sizeof(SLText);
79  stats.numBytes += (SLuint)_text.length();
80  stats.numNodes++;
81  stats.numTriangles += (SLuint)_text.length() * 2 + 2;
82 }
SLText creates a mesh using a textured font from SLTexFont.
Definition: SLText.h:30
SLuint numNodes
NO. of children nodes.
Definition: SLNode.h:38
SLuint numTriangles
NO. of triangles in mesh.
Definition: SLNode.h:47
SLuint numBytes
NO. of bytes allocated.
Definition: SLNode.h:39

◆ text()

SLstring SLText::text ( )
inline

Definition at line 48 of file SLText.h.

48 { return _text; }

◆ updateAABBRec()

SLAABBox & SLText::updateAABBRec ( SLbool  updateAlsoAABBinOS)
overridevirtual

SLText::buildAABB builds and returns the axis-aligned bounding box.

Reimplemented from SLNode.

Definition at line 87 of file SLText.cpp.

88 {
90 
91  // calculate min & max in object space
92  SLVec3f minOS(0, 0, -0.01f);
93  SLVec3f maxOS(size.x, size.y, 0.01f);
94 
95  // apply world matrix: this overwrites the AABB of the group
96  if (updateAlsoAABBinOS)
97  _aabb.fromOStoWS(minOS, maxOS, updateAndGetWM());
98 
99  return _aabb;
100 }
void fromOStoWS(const SLVec3f &minOS, const SLVec3f &maxOS, const SLMat4f &wm)
Recalculate min and max after transformation in world coords.
Definition: SLAABBox.cpp:46
SLAABBox _aabb
axis aligned bounding box
Definition: SLNode.h:360
SLVec2f size()
Definition: SLText.h:50
T y
Definition: SLVec2.h:30
T x
Definition: SLVec2.h:30

Member Data Documentation

◆ _color

SLCol4f SLText::_color
protected

RGBA-Color of the text.

Definition at line 59 of file SLText.h.

◆ _font

SLTexFont* SLText::_font
protected

Font pointer of the preloaded font.

Definition at line 58 of file SLText.h.

◆ _lineH

SLfloat SLText::_lineH
protected

Line height factor for wrapped text.

Definition at line 61 of file SLText.h.

◆ _maxW

SLfloat SLText::_maxW
protected

Max. width in pix. for wrapped text.

Definition at line 60 of file SLText.h.

◆ _text

SLstring SLText::_text
protected

Text of the button.

Definition at line 57 of file SLText.h.

◆ _vao

SLGLVertexArray SLText::_vao
protected

Vertex array for rendering.

Definition at line 62 of file SLText.h.


The documentation for this class was generated from the following files: