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

Class for texture blending scene. More...

#include <AppDemoSceneTextureBlend.h>

Inheritance diagram for AppDemoSceneTextureBlend:
[legend]

Public Member Functions

 AppDemoSceneTextureBlend ()
 
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
 

Private Attributes

SLGLTexture_t1
 
SLGLTexture_t2
 
SLGLProgram_sp
 

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 texture blending scene.

Definition at line 20 of file AppDemoSceneTextureBlend.h.

Constructor & Destructor Documentation

◆ AppDemoSceneTextureBlend()

AppDemoSceneTextureBlend::AppDemoSceneTextureBlend ( )

Definition at line 20 of file AppDemoSceneTextureBlend.cpp.

20  : SLScene("Texture Blending Test")
21 {
22  info("Texture map blending with depth sorting. Transparent tree rectangles in view "
23  "frustum are rendered back to front. You can turn on/off alpha sorting in the "
24  "menu Preferences of press key J.");
25 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneTextureBlend::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 49 of file AppDemoSceneTextureBlend.cpp.

50 {
51  SLMaterial* m1 = new SLMaterial(am,
52  "m1",
53  SLCol4f(1, 1, 1),
54  SLCol4f(0, 0, 0),
55  100);
56  SLMaterial* m2 = new SLMaterial(am,
57  "m2",
58  SLCol4f(1, 1, 1),
59  SLCol4f(0, 0, 0),
60  100);
61  m1->program(_sp);
62  m1->addTexture(_t1);
63  m2->addTexture(_t2);
64 
65  SLCamera* cam1 = new SLCamera("Camera 1");
66  cam1->translation(6.5f, 0.5f, -18);
67  cam1->lookAt(0, 0, 0);
68  cam1->focalDist(18);
69  cam1->background().colors(SLCol4f(0.6f, 0.6f, 1));
70  cam1->setInitialState();
72 
73  SLLightSpot* light = new SLLightSpot(am, this, 0.1f);
74  light->translation(5, 5, 5);
75  light->lookAt(0, 0, 0);
76  light->attenuation(1, 0, 0);
77 
78  // Build arrays for polygon vertices and texture coordinates for tree
79  SLVVec3f pNW, pSE;
80  SLVVec2f tNW, tSE;
81  pNW.push_back(SLVec3f(0, 0, 0));
82  tNW.push_back(SLVec2f(0.5f, 0.0f));
83  pNW.push_back(SLVec3f(1, 0, 0));
84  tNW.push_back(SLVec2f(1.0f, 0.0f));
85  pNW.push_back(SLVec3f(1, 2, 0));
86  tNW.push_back(SLVec2f(1.0f, 1.0f));
87  pNW.push_back(SLVec3f(0, 2, 0));
88  tNW.push_back(SLVec2f(0.5f, 1.0f));
89  pSE.push_back(SLVec3f(-1, 0, 0));
90  tSE.push_back(SLVec2f(0.0f, 0.0f));
91  pSE.push_back(SLVec3f(0, 0, 0));
92  tSE.push_back(SLVec2f(0.5f, 0.0f));
93  pSE.push_back(SLVec3f(0, 2, 0));
94  tSE.push_back(SLVec2f(0.5f, 1.0f));
95  pSE.push_back(SLVec3f(-1, 2, 0));
96  tSE.push_back(SLVec2f(0.0f, 1.0f));
97 
98  // Build tree out of 4 polygons
99  SLNode* p1 = new SLNode(new SLPolygon(am, pNW, tNW, "Tree+X", m1));
100  SLNode* p2 = new SLNode(new SLPolygon(am, pNW, tNW, "Tree-Z", m1));
101  p2->rotate(90, 0, 1, 0);
102  SLNode* p3 = new SLNode(new SLPolygon(am, pSE, tSE, "Tree-X", m1));
103  SLNode* p4 = new SLNode(new SLPolygon(am, pSE, tSE, "Tree+Z", m1));
104  p4->rotate(90, 0, 1, 0);
105 
106  // Turn face culling off so that we see both sides
107  p1->drawBits()->on(SL_DB_CULLOFF);
108  p2->drawBits()->on(SL_DB_CULLOFF);
109  p3->drawBits()->on(SL_DB_CULLOFF);
110  p4->drawBits()->on(SL_DB_CULLOFF);
111 
112  // Build tree group
113  SLNode* tree = new SLNode("grTree");
114  tree->addChild(p1);
115  tree->addChild(p2);
116  tree->addChild(p3);
117  tree->addChild(p4);
118 
119  // Build arrays for polygon vertices and texcoords for ground
120  SLVVec3f pG;
121  SLVVec2f tG;
122  SLfloat size = 22.0f;
123  pG.push_back(SLVec3f(-size, 0, size));
124  tG.push_back(SLVec2f(0, 0));
125  pG.push_back(SLVec3f(size, 0, size));
126  tG.push_back(SLVec2f(30, 0));
127  pG.push_back(SLVec3f(size, 0, -size));
128  tG.push_back(SLVec2f(30, 30));
129  pG.push_back(SLVec3f(-size, 0, -size));
130  tG.push_back(SLVec2f(0, 30));
131 
132  SLNode* scene = new SLNode("grScene");
133  this->root3D(scene);
134  scene->addChild(light);
135  scene->addChild(tree);
136  scene->addChild(new SLNode(new SLPolygon(am,
137  pG,
138  tG,
139  "Ground",
140  m2)));
141 
142  // create 21*21*21-1 references around the center tree
143  SLint res = 10;
144  for (SLint iZ = -res; iZ <= res; ++iZ)
145  {
146  for (SLint iX = -res; iX <= res; ++iX)
147  {
148  if (iX != 0 || iZ != 0)
149  {
150  SLNode* t = tree->copyRec();
151  t->translate(float(iX) * 2 + Utils::random(0.7f, 1.4f),
152  0,
153  float(iZ) * 2 + Utils::random(0.7f, 1.4f),
154  TS_object);
155  t->rotate(Utils::random(0.f, 90.f), 0, 1, 0);
156  t->scale(Utils::random(0.5f, 1.0f));
157  scene->addChild(t);
158  }
159  }
160  }
161 
162  scene->addChild(cam1);
163 
164  sv->camera(cam1);
165 }
float SLfloat
Definition: SL.h:173
int SLint
Definition: SL.h:170
#define SL_DB_CULLOFF
Turn off face culling.
Definition: SLDrawBits.h:28
@ TS_object
Definition: SLEnums.h:210
vector< SLVec2f > SLVVec2f
Definition: SLVec2.h:143
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
vector< SLVec3f > SLVVec3f
Definition: SLVec3.h:325
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
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
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
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 on(SLuint bit)
Turns the specified bit on.
Definition: SLDrawBits.h:51
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
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
void addTexture(SLGLTexture *texture)
Adds the passed texture to the equivalent texture type vector.
Definition: SLMaterial.cpp:348
void program(SLGLProgram *sp)
Definition: SLMaterial.h:205
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 rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945
void scale(SLfloat s)
Definition: SLNode.h:640
virtual SLNode * copyRec()
Definition: SLNode.cpp:572
SLDrawBits * drawBits()
Definition: SLNode.h:299
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
SLPolygon creates a convex polyon mesh.
Definition: SLPolygon.h:29
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
float random(float min, float max)
Returns a uniform distributed random float number between min and max.
Definition: Utils.h:265

◆ registerAssetsToLoad()

void AppDemoSceneTextureBlend::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 AppDemoSceneTextureBlend.cpp.

29 {
32  "tree1_1024_C.png",
33  GL_LINEAR_MIPMAP_LINEAR,
34  GL_LINEAR,
35  TT_diffuse,
36  GL_CLAMP_TO_EDGE,
37  GL_CLAMP_TO_EDGE);
40  "grass0512_C.jpg",
41  GL_LINEAR_MIPMAP_LINEAR,
42  GL_LINEAR);
44  AppCommon::shaderPath + "PerVrtTm.vert",
45  AppCommon::shaderPath + "PerVrtTm.frag");
46 }
@ TT_diffuse
Definition: SLGLTexture.h:78
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
static SLstring shaderPath
Path to GLSL shader programs.
Definition: AppCommon.h:84
void addProgramToLoad(SLGLProgram *&program, const SLstring &vertShaderFile, const SLstring &fragShaderFile)
Add generic GLSL program with shader files to load.
void addTextureToLoad(SLGLTexture *&texture, const SLstring &path, SLint min_filter=GL_LINEAR_MIPMAP_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT)
Add 2D textures with internal image allocation.

Member Data Documentation

◆ _sp

SLGLProgram* AppDemoSceneTextureBlend::_sp
private

Definition at line 47 of file AppDemoSceneTextureBlend.h.

◆ _t1

SLGLTexture* AppDemoSceneTextureBlend::_t1
private

Definition at line 45 of file AppDemoSceneTextureBlend.h.

◆ _t2

SLGLTexture* AppDemoSceneTextureBlend::_t2
private

Definition at line 46 of file AppDemoSceneTextureBlend.h.


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