SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppDemoSceneTextureFilter.cpp
Go to the documentation of this file.
1 /**
2  * \file AppDemoSceneTextureFilter.cpp
3  * \brief Implementation for an SLScene inherited class
4  * \details For more info about App framework and the scene assembly see:
5  * https://cpvrlab.github.io/SLProject4/app-framework.html
6  * \date May 2024
7  * \authors Marino von Wattenwyl
8  * \copyright http://opensource.org/licenses/GPL-3.0
9  * \remarks Please use clangformat to format the code. See more code style on
10  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
11 */
12 
14 #include <SLAssetLoader.h>
15 #include <SLLightSpot.h>
16 #include <SLPolygon.h>
17 #include <SLSphere.h>
18 #include <AppCommon.h>
19 
20 //-----------------------------------------------------------------------------
22 {
23  info("Texture minification filters: "
24  "Bottom: nearest, left: linear, top: linear mipmap, right: anisotropic. "
25  "The center sphere uses a 3D texture with linear filtering.");
26 }
27 //-----------------------------------------------------------------------------
28 //! All assets the should be loaded in parallel must be registered in here.
30 {
33  "brick0512_C.png",
34  GL_LINEAR,
35  GL_LINEAR);
38  "brick0512_C.png",
39  GL_NEAREST,
40  GL_NEAREST);
43  "brick0512_C.png",
44  GL_LINEAR_MIPMAP_LINEAR,
45  GL_LINEAR);
48  "brick0512_C.png",
50  GL_LINEAR);
52  256,
54  "Wave_radial10_256C.jpg");
56  AppCommon::shaderPath + "TextureOnly3D.vert",
57  AppCommon::shaderPath + "TextureOnly3D.frag");
58 }
59 //-----------------------------------------------------------------------------
60 //! After parallel loading of the assets the scene gets assembled in here.
62 {
63  // define materials with textureOnly shader, no light needed
64  SLMaterial* matB = new SLMaterial(am,
65  "matB",
66  _texB,
67  nullptr,
68  nullptr,
69  nullptr,
71  SLMaterial* matL = new SLMaterial(am,
72  "matL",
73  _texL,
74  nullptr,
75  nullptr,
76  nullptr,
78  SLMaterial* matT = new SLMaterial(am,
79  "matT",
80  _texT,
81  nullptr,
82  nullptr,
83  nullptr,
85  SLMaterial* matR = new SLMaterial(am,
86  "matR",
87  _texR,
88  nullptr,
89  nullptr,
90  nullptr,
92 
93  // build polygons for bottom, left, top & right side
94  SLVVec3f VB;
95  VB.push_back(SLVec3f(-0.5f, -0.5f, 1.0f));
96  VB.push_back(SLVec3f(0.5f, -0.5f, 1.0f));
97  VB.push_back(SLVec3f(0.5f, -0.5f, -2.0f));
98  VB.push_back(SLVec3f(-0.5f, -0.5f, -2.0f));
99  SLVVec2f T;
100  T.push_back(SLVec2f(0.0f, 2.0f));
101  T.push_back(SLVec2f(0.0f, 0.0f));
102  T.push_back(SLVec2f(6.0f, 0.0f));
103  T.push_back(SLVec2f(6.0f, 2.0f));
104  SLNode* polyB = new SLNode(new SLPolygon(am, VB, T, "PolygonB", matB));
105 
106  SLVVec3f VL;
107  VL.push_back(SLVec3f(-0.5f, 0.5f, 1.0f));
108  VL.push_back(SLVec3f(-0.5f, -0.5f, 1.0f));
109  VL.push_back(SLVec3f(-0.5f, -0.5f, -2.0f));
110  VL.push_back(SLVec3f(-0.5f, 0.5f, -2.0f));
111  SLNode* polyL = new SLNode(new SLPolygon(am, VL, T, "PolygonL", matL));
112 
113  SLVVec3f VT;
114  VT.push_back(SLVec3f(0.5f, 0.5f, 1.0f));
115  VT.push_back(SLVec3f(-0.5f, 0.5f, 1.0f));
116  VT.push_back(SLVec3f(-0.5f, 0.5f, -2.0f));
117  VT.push_back(SLVec3f(0.5f, 0.5f, -2.0f));
118  SLNode* polyT = new SLNode(new SLPolygon(am, VT, T, "PolygonT", matT));
119 
120  SLVVec3f VR;
121  VR.push_back(SLVec3f(0.5f, -0.5f, 1.0f));
122  VR.push_back(SLVec3f(0.5f, 0.5f, 1.0f));
123  VR.push_back(SLVec3f(0.5f, 0.5f, -2.0f));
124  VR.push_back(SLVec3f(0.5f, -0.5f, -2.0f));
125  SLNode* polyR = new SLNode(new SLPolygon(am, VR, T, "PolygonR", matR));
126 
127  // 3D Texture Mapping on a pyramid
128  SLMaterial* mat3D = new SLMaterial(am,
129  "mat3D",
130  _tex3D,
131  nullptr,
132  nullptr,
133  nullptr,
134  _spr3D);
135 
136  // Create 3D textured pyramid mesh and node
137  SLMesh* pyramid = new SLMesh(am, "Pyramid");
138  pyramid->mat(mat3D);
139  pyramid->P = {{-1, -1, 1},
140  {1, -1, 1},
141  {1, -1, -1},
142  {-1, -1, -1},
143  {0, 2, 0}};
144  pyramid->I16 = {0, 3, 1, 1, 3, 2, 4, 0, 1, 4, 1, 2, 4, 2, 3, 4, 3, 0};
145  SLNode* pyramidNode = new SLNode(pyramid, "Pyramid");
146  pyramidNode->scale(0.2f);
147  pyramidNode->translate(0, 0, -3);
148 
149  // Create 3D textured sphere mesh and node
150  SLNode* sphere = new SLNode(new SLSphere(am,
151  0.2f,
152  16,
153  16,
154  "Sphere",
155  mat3D));
156  SLCamera* cam1 = new SLCamera("Camera 1");
157  cam1->translation(0, 0, 2.6f);
158  cam1->lookAt(0, 0, 0);
159  cam1->focalDist(2.2f);
160  cam1->background().colors(SLCol4f(0.2f, 0.2f, 0.2f));
161  cam1->setInitialState();
163 
164  SLNode* scene = new SLNode();
165  this->root3D(scene);
166  scene->addChild(polyB);
167  scene->addChild(polyL);
168  scene->addChild(polyT);
169  scene->addChild(polyR);
170  scene->addChild(sphere);
171  scene->addChild(cam1);
172  sv->camera(cam1);
173 }
174 //-----------------------------------------------------------------------------
The AppCommon class holds the top-level instances of the app-demo.
Class declaration for an SLScene inherited class.
@ SP_textureOnly
#define SL_ANISOTROPY_MAX
Definition: SLGLTexture.h:34
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
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
static SLstring shaderPath
Path to GLSL shader programs.
Definition: AppCommon.h:84
void registerAssetsToLoad(SLAssetLoader &al) override
All scene specific assets have to be registered for async loading in here.
void assemble(SLAssetManager *am, SLSceneView *sv) override
After parallel loading of the assets the scene gets assembled in here.
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.
Toplevel holder of the assets meshes, materials, textures and shaders.
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
static SLGLProgramGeneric * get(SLStdShaderProg id)
Get program reference for given id.
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
An SLMesh object is a triangulated mesh, drawn with one draw call.
Definition: SLMesh.h:134
SLVushort I16
Vector of vertex indices 16 bit.
Definition: SLMesh.h:214
SLVVec3f P
Vector for vertex positions layout (location = 0)
Definition: SLMesh.h:203
SLMaterial * mat() const
Definition: SLMesh.h:177
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
SLPolygon creates a convex polyon mesh.
Definition: SLPolygon.h:29
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SLstring & info()
Definition: SLScene.h:102
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
SLSphere creates a sphere mesh based on SLSpheric w. 180 deg polar angle.
Definition: SLSphere.h:33