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

Class for 2D and 3D text scene. More...

#include <AppDemoScene2Dand3DText.h>

Inheritance diagram for AppDemoScene2Dand3DText:
[legend]

Public Member Functions

 AppDemoScene2Dand3DText ()
 
void registerAssetsToLoad (SLAssetLoader &al) override
 All scene specific assets have to be registered for async loading in here. More...
 
void assemble (SLAssetManager *am, SLSceneView *sv) override
 After parallel loading of the assets the scene gets assembled in here. More...
 
- Public Member Functions inherited from SLScene
 SLScene (const SLstring &name)
 
 ~SLScene () override
 
void initOculus (SLstring shaderDir)
 
void root3D (SLNode *root3D)
 
void root2D (SLNode *root2D)
 
void skybox (SLSkybox *skybox)
 
void stopAnimations (SLbool stop)
 
void info (SLstring i)
 
void loadTimeMS (SLfloat loadTimeMS)
 
SLAnimManageranimManager ()
 
SLAssetManagerassetManager ()
 
SLNoderoot3D ()
 
SLNoderoot2D ()
 
SLSkyboxskybox ()
 
SLstringinfo ()
 
SLfloat elapsedTimeMS () const
 
SLfloat elapsedTimeSec () const
 
SLVEventHandlereventHandlers ()
 
SLfloat loadTimeMS () const
 
SLVLightlights ()
 
SLfloat fps () const
 
AvgFloatframeTimesMS ()
 
AvgFloatupdateTimesMS ()
 
AvgFloatupdateAnimTimesMS ()
 
AvgFloatupdateAABBTimesMS ()
 
AvgFloatupdateDODTimesMS ()
 
SLNodesingleNodeSelected ()
 Returns the node if only one is selected. See also SLMesh::selectNodeMesh. More...
 
SLMeshsingleMeshFullSelected ()
 Returns the node if only one is selected. See also SLMesh::selectNodeMesh. More...
 
SLVNodeselectedNodes ()
 
SLVMeshselectedMeshes ()
 
SLbool stopAnimations () const
 
SLint numSceneCameras ()
 Returns the number of camera nodes in the scene. More...
 
SLCameranextCameraInScene (SLCamera *activeSVCam)
 Returns the next camera in the scene if there is one. More...
 
bool onUpdate (bool renderTypeIsRT, bool voxelsAreShown, bool forceCPUSkinning)
 Updates animations and AABBs. More...
 
void init (SLAssetManager *am)
 
virtual void unInit ()
 
void selectNodeMesh (SLNode *nodeToSelect, SLMesh *meshToSelect)
 Handles the full mesh selection from double-clicks. More...
 
void deselectAllNodesAndMeshes ()
 Deselects all nodes and its meshes. More...
 
SLGLOculusoculus ()
 
- 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
 

Additional Inherited Members

- Protected Attributes inherited from SLScene
SLVLight _lights
 Vector of all lights. More...
 
SLVEventHandler _eventHandlers
 Vector of all event handler. More...
 
SLAnimManager _animManager
 Animation manager instance. More...
 
SLAssetManager_assetManager
 Pointer to the external assetManager. More...
 
SLNode_root3D
 Root node for 3D scene. More...
 
SLNode_root2D
 Root node for 2D scene displayed in ortho projection. More...
 
SLSkybox_skybox
 pointer to skybox More...
 
SLstring _info
 scene info string More...
 
SLVNode _selectedNodes
 Vector of selected nodes. See SLMesh::selectNodeMesh. More...
 
SLVMesh _selectedMeshes
 Vector of selected meshes. See SLMesh::selectNodeMesh. More...
 
SLfloat _loadTimeMS
 time to load scene in ms More...
 
SLfloat _frameTimeMS
 Last frame time in ms. More...
 
SLfloat _lastUpdateTimeMS
 Last time after update in ms. More...
 
SLfloat _fps
 Averaged no. of frames per second. More...
 
AvgFloat _frameTimesMS
 Averaged total time per frame in ms. More...
 
AvgFloat _updateTimesMS
 Averaged time for update in ms. More...
 
AvgFloat _updateAABBTimesMS
 Averaged time for update the nodes AABB in ms. More...
 
AvgFloat _updateAnimTimesMS
 Averaged time for update the animations in ms. More...
 
AvgFloat _updateDODTimesMS
 Averaged time for update the SLEntities graph. More...
 
SLbool _stopAnimations
 Global flag for stopping all animations. More...
 
std::unique_ptr< SLGLOculus_oculus
 Oculus Rift interface. More...
 
- Protected Attributes inherited from SLObject
SLstring _name
 name of an object More...
 
SLstring _url
 uniform resource locator More...
 

Detailed Description

Class for 2D and 3D text scene.

Definition at line 20 of file AppDemoScene2Dand3DText.h.

Constructor & Destructor Documentation

◆ AppDemoScene2Dand3DText()

AppDemoScene2Dand3DText::AppDemoScene2Dand3DText ( )

Definition at line 21 of file AppDemoScene2Dand3DText.cpp.

21  : SLScene("2D and 3D Text Scene")
22 {
23  info("All 3D objects are in the _root3D scene and the center text is in the _root2D scene "
24  "and rendered in orthographic projection in screen space.");
25 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoScene2Dand3DText::assemble ( SLAssetManager am,
SLSceneView sv 
)
overridevirtual

After parallel loading of the assets the scene gets assembled in here.

Remarks
All scene-specific assets have to be loaded async by overriding SLScene::registerAssetsToLoad and SLScene::assemble. Async loading and assembling means that it happens in a parallel thread and that in there are no OpenGL calls allowed. OpenGL calls are only allowed in the main thread. It is important that all object instantiations within SLScene::assemble do NOT call any OpenGL functions (gl*) because they happen in a parallel thread. All objects that get rendered have to do their initialization when they are used the first time during rendering in the main thread.

Reimplemented from SLScene.

Definition at line 33 of file AppDemoScene2Dand3DText.cpp.

34 {
35  SLMaterial* m1 = new SLMaterial(am, "m1", SLCol4f::RED);
36 
37  SLCamera* cam1 = new SLCamera("Camera 1");
38  cam1->clipNear(0.1f);
39  cam1->clipFar(100);
40  cam1->translation(0, 0, 5);
41  cam1->lookAt(0, 0, 0);
42  cam1->focalDist(5);
43  cam1->background().colors(SLCol4f(0.1f, 0.1f, 0.1f));
44  cam1->setInitialState();
46 
47  SLLightSpot* light1 = new SLLightSpot(am,
48  this,
49  10,
50  10,
51  10,
52  0.3f);
53  light1->powers(0.2f, 0.8f, 1.0f);
54  light1->attenuation(1, 0, 0);
55 
56  // Because all text objects get their sizes in pixels we have to scale them down
57  SLfloat scale = 0.01f;
58  SLstring txt = "This is text in 3D with font07";
60  SLNode* t07 = new SLText(txt, SLAssetManager::font07);
61  t07->translate(-size.x * 0.5f * scale, 1.0f, 0);
62  t07->scale(scale);
63 
64  txt = "This is text in 3D with font09";
66  SLNode* t09 = new SLText(txt, SLAssetManager::font09);
67  t09->translate(-size.x * 0.5f * scale, 0.8f, 0);
68  t09->scale(scale);
69 
70  txt = "This is text in 3D with font12";
72  SLNode* t12 = new SLText(txt, SLAssetManager::font12);
73  t12->translate(-size.x * 0.5f * scale, 0.6f, 0);
74  t12->scale(scale);
75 
76  txt = "This is text in 3D with font20";
78  SLNode* t20 = new SLText(txt, SLAssetManager::font20);
79  t20->translate(-size.x * 0.5f * scale, -0.8f, 0);
80  t20->scale(scale);
81 
82  txt = "This is text in 3D with font22";
84  SLNode* t22 = new SLText(txt, SLAssetManager::font22);
85  t22->translate(-size.x * 0.5f * scale, -1.2f, 0);
86  t22->scale(scale);
87 
88  // Now create 2D text but don't scale it (all sizes in pixels)
89  txt = "This is text in 2D with font16";
91  SLNode* t2D16 = new SLText(txt, SLAssetManager::font16);
92  t2D16->translate(-size.x * 0.5f, 0, 0);
93 
94  // Assemble 3D scene as usual with camera and light
95  SLNode* scene3D = new SLNode("root3D");
96  this->root3D(scene3D);
97  scene3D->addChild(cam1);
98  scene3D->addChild(light1);
99  scene3D->addChild(new SLNode(new SLSphere(am,
100  0.5f,
101  32,
102  32,
103  "Sphere",
104  m1)));
105  scene3D->addChild(t07);
106  scene3D->addChild(t09);
107  scene3D->addChild(t12);
108  scene3D->addChild(t20);
109  scene3D->addChild(t22);
110 
111  // Assemble 2D scene
112  SLNode* scene2D = new SLNode("root2D");
113  this->root2D(scene2D);
114  scene2D->addChild(t2D16);
115 
116  sv->camera(cam1);
117  sv->doWaitOnIdle(true);
118 }
float SLfloat
Definition: SL.h:173
string SLstring
Definition: SL.h:158
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
static SLDeviceRotation devRot
Mobile device rotation from IMU.
Definition: AppCommon.h:64
static SLDeviceLocation devLoc
Mobile device location from GPS.
Definition: AppCommon.h:65
static SLTexFont * font20
20 pixel high fixed size font
static SLTexFont * font09
9 pixel high fixed size font
static SLTexFont * font22
22 pixel high fixed size font
static SLTexFont * font07
7 pixel high fixed size font
static SLTexFont * font12
12 pixel high fixed size font
static SLTexFont * font16
16 pixel high fixed size font
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
void clipFar(const SLfloat cFar)
Definition: SLCamera.h:109
void clipNear(const SLfloat cNear)
Definition: SLCamera.h:108
void devRotLoc(SLDeviceRotation *devRot, SLDeviceLocation *devLoc)
Definition: SLCamera.h:120
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLBackground & background()
Definition: SLCamera.h:165
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
void powers(SLfloat ambiPow, SLfloat diffPow, SLfloat specPow, const SLCol4f &ambiDiffSpecCol=SLCol4f::WHITE)
Sets the ambient, diffuse and specular powers all with the same color.
Definition: SLLight.h:74
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void addChild(SLNode *child)
Definition: SLNode.cpp:207
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
void scale(SLfloat s)
Definition: SLNode.h:640
void setInitialState()
Definition: SLNode.cpp:1084
void lookAt(SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
Definition: SLNode.h:652
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
SLNode * root2D()
Definition: SLScene.h:100
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
void doWaitOnIdle(SLbool doWI)
Definition: SLSceneView.h:149
SLSphere creates a sphere mesh based on SLSpheric w. 180 deg polar angle.
Definition: SLSphere.h:33
SLVec2f calcTextSize(const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeightFactor=1.5f)
Definition: SLTexFont.cpp:243
SLText creates a mesh using a textured font from SLTexFont.
Definition: SLText.h:30
T x
Definition: SLVec2.h:30
static SLVec4 RED
Definition: SLVec4.h:216

◆ registerAssetsToLoad()

void AppDemoScene2Dand3DText::registerAssetsToLoad ( SLAssetLoader al)
overridevirtual

All scene specific assets have to be registered for async loading in here.

All assets the should be loaded in parallel must be registered in here.

Remarks
All scene sspecific assets have to be loaded async by overriding SLScene::registerAssetsToLoad and SLScene::assemble. Async loading and assembling means that it happens in a parallel thread and that in there are no OpenGL calls allowed. OpenGL calls are only allowed in the main thread.

Reimplemented from SLScene.

Definition at line 28 of file AppDemoScene2Dand3DText.cpp.

29 {
30 }

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