From cbfcd09edd956806a048b7e1a6f20606275d4b0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr>
Date: Wed, 29 May 2024 14:17:04 +0200
Subject: [PATCH] Add Skybox on ertain scene

---
 ParticleGenerator/res/config/imgui.ini            |  2 +-
 .../src/Interface/Scene/SceneParticle.cpp         |  1 +
 ParticleGenerator/src/Mesh/Skybox.hpp             |  3 +--
 ParticleGenerator/src/Scene/Scene.cpp             |  2 +-
 ParticleGenerator/src/Scene/Scene.hpp             |  8 +++++---
 .../src/Scene/Scenes/MeshGenerator.cpp            | 15 +++++++++++++--
 .../src/Scene/Scenes/MeshGenerator.hpp            |  2 ++
 .../src/Scene/Scenes/MeshGeneratorModel.cpp       | 13 +++++++++++--
 .../src/Scene/Scenes/MeshGeneratorModel.hpp       |  2 ++
 ParticleGenerator/src/Scene/Scenes/MultyPath.cpp  | 13 +++++++++++++
 ParticleGenerator/src/Scene/Scenes/MultyPath.hpp  |  2 ++
 ParticleGenerator/src/Scene/Scenes/Path.cpp       |  4 +++-
 .../src/Scene/Scenes/PathAnimated.cpp             |  2 ++
 .../src/Scene/Scenes/PathPregenerated.cpp         |  2 ++
 ParticleGenerator/src/Scene/Scenes/Physic.cpp     |  3 ++-
 .../src/Scene/Scenes/PhysicSprite.cpp             |  3 ++-
 16 files changed, 63 insertions(+), 14 deletions(-)

diff --git a/ParticleGenerator/res/config/imgui.ini b/ParticleGenerator/res/config/imgui.ini
index c470b92..17856c7 100644
--- a/ParticleGenerator/res/config/imgui.ini
+++ b/ParticleGenerator/res/config/imgui.ini
@@ -4,5 +4,5 @@ Size=400,400
 
 [Window][Particle Generator]
 Pos=60,60
-Size=848,714
+Size=733,329
 
diff --git a/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp b/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp
index 52a7e85..0f7a62d 100644
--- a/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp
+++ b/ParticleGenerator/src/Interface/Scene/SceneParticle.cpp
@@ -47,5 +47,6 @@ namespace pg::interface {
         ImGui::Checkbox("Enable Spawning", &this->_scene->_enableSpawn);
         ImGui::Checkbox("Enable Rendering", &this->_scene->_enableRender);
         ImGui::Checkbox("Freezing", &this->_scene->_enableFreeze);
+        ImGui::Checkbox("Wireframe", &this->_scene->_enableWireframe);
     }
 }
\ No newline at end of file
diff --git a/ParticleGenerator/src/Mesh/Skybox.hpp b/ParticleGenerator/src/Mesh/Skybox.hpp
index 888ec04..458f305 100644
--- a/ParticleGenerator/src/Mesh/Skybox.hpp
+++ b/ParticleGenerator/src/Mesh/Skybox.hpp
@@ -18,8 +18,7 @@ namespace pg {
             
 
         public:
-            SkyBox() = delete;
-            SkyBox(const std::string &, const std::string &);
+            SkyBox(const std::string & = "res/shaders/system/Skybox.vert", const std::string & = "res/shaders/system/Skybox.frag");
 
             inline const CubemapMaterial & material() const {return this->_material;}
 
diff --git a/ParticleGenerator/src/Scene/Scene.cpp b/ParticleGenerator/src/Scene/Scene.cpp
index 5e8ded0..14ce37b 100644
--- a/ParticleGenerator/src/Scene/Scene.cpp
+++ b/ParticleGenerator/src/Scene/Scene.cpp
@@ -2,5 +2,5 @@
 
 namespace pg::scene {
     SceneParticle::SceneParticle(int max)
-    : Scene(), _max(max), _spawn(1), _frequence(500), _lifetime(5), _enableRender(true), _enableSpawn(true), _enableFreeze(false) {}
+    : Scene(), _max(max), _spawn(1), _frequence(500), _lifetime(5), _enableRender(true), _enableSpawn(true), _enableFreeze(false), _enableWireframe(false) {}
 }
\ No newline at end of file
diff --git a/ParticleGenerator/src/Scene/Scene.hpp b/ParticleGenerator/src/Scene/Scene.hpp
index f3bb177..a37777e 100644
--- a/ParticleGenerator/src/Scene/Scene.hpp
+++ b/ParticleGenerator/src/Scene/Scene.hpp
@@ -35,6 +35,7 @@ namespace pg::scene {
             bool _enableRender;
             bool _enableSpawn;
             bool _enableFreeze;
+            bool _enableWireframe;
 
         protected:
             ParticleContainer _particles;
@@ -48,9 +49,10 @@ namespace pg::scene {
             inline int getSpawnCount() const {return this->_spawn;}
             inline int getSpawnFrequence() const {return this->_frequence;}
             inline int getLifetime() const {return this->_lifetime;}
-            inline bool isRenderEnable() {return this->_enableRender;}
-            inline bool isSpawnEnable() {return this->_enableSpawn;}
-            inline bool isFreezeEnable() {return this->_enableFreeze;}
+            inline bool isRenderEnable() const {return this->_enableRender;}
+            inline bool isSpawnEnable() const {return this->_enableSpawn;}
+            inline bool isFreezeEnable() const {return this->_enableFreeze;}
+            inline bool isWireframeEnable() const {return this->_enableWireframe;}
 
             inline void setSpawnCount(int sc) {this->_spawn = sc;}
             inline void setSpawnFrequence(int sf) {this->_frequence = sf;}
diff --git a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp
index 4f8228b..6035e00 100644
--- a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp
+++ b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.cpp
@@ -26,6 +26,15 @@ namespace pg::scene {
             this->changeMesh("res/models/sphere.obj");
         }
 
+        this->_skybox.load({
+            "res/textures/skybox/snow/right.png",
+            "res/textures/skybox/snow/left.png",
+            "res/textures/skybox/snow/top.png",
+            "res/textures/skybox/snow/bottom.png",
+            "res/textures/skybox/snow/front.png",
+            "res/textures/skybox/snow/back.png"
+        }, Texture::AUTO, false);
+
         if(!this->_meshProgram.usable()) {
             Source vert("res/shaders/scene/Color.vert", Source::Categorie::VERTEX);
             Source frag("res/shaders/scene/Color.frag", Source::Categorie::FRAGMENT);
@@ -98,6 +107,8 @@ namespace pg::scene {
 
         // --------
 
+        this->_skybox.draw(camera);
+
         this->_meshProgram.use();
 
         glm::mat4 model = glm::mat4(1.f);
@@ -144,16 +155,16 @@ namespace pg::scene {
 
             pg::error::OpenGLError::check();
 
+            glPolygonMode(GL_FRONT_AND_BACK, this->isWireframeEnable() ? GL_LINE : GL_FILL);
             if(this->isRenderEnable()) {
                 this->_billboard.draw(this->_particles.size());
             }
+            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
             pg::error::OpenGLError::check();
 
             particle_accumulator += 1024;
         }
-
-        // --------
     }
 
     void MeshGenerator::destroy() {
diff --git a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp
index d5382bc..aab0596 100644
--- a/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp
+++ b/ParticleGenerator/src/Scene/Scenes/MeshGenerator.hpp
@@ -6,6 +6,7 @@
 #include <memory>
 
 #include "../../Mesh/Mesh.hpp"
+#include "../../Mesh/Skybox.hpp"
 #include "../../Mesh/Billboard.hpp"
 #include "../../Renderer/Renderer.hpp"
 #include "../../Particle/generator/PhysicsGenerator.hpp"
@@ -15,6 +16,7 @@ namespace pg::scene {
     class MeshGenerator : public SceneParticle {
         private:
             Mesh _mesh;
+            SkyBox _skybox;
             Program _meshProgram;
             glm::vec3 _meshPosition;
             glm::vec3 _meshRotation;
diff --git a/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.cpp b/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.cpp
index 8803b22..978742c 100644
--- a/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.cpp
+++ b/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.cpp
@@ -26,6 +26,15 @@ namespace pg::scene {
             this->changeMesh("res/models/sphere.obj");
         }
 
+        this->_skybox.load({
+            "res/textures/skybox/snow/right.png",
+            "res/textures/skybox/snow/left.png",
+            "res/textures/skybox/snow/top.png",
+            "res/textures/skybox/snow/bottom.png",
+            "res/textures/skybox/snow/front.png",
+            "res/textures/skybox/snow/back.png"
+        }, Texture::AUTO, false);
+
         if(!this->_meshParticle.isGenerated()) {
             this->changeMeshParticle("res/models/sphere.obj");
         }
@@ -116,8 +125,6 @@ namespace pg::scene {
 
         pg::error::OpenGLError::check();
 
-        // --------
-
         size_t particle_accumulator = 0;
         while(particle_accumulator < this->_particles.size()) {
             std::vector<glm::mat4> models;
@@ -142,9 +149,11 @@ namespace pg::scene {
 
             pg::error::OpenGLError::check();
 
+            glPolygonMode(GL_FRONT_AND_BACK, this->isWireframeEnable() ? GL_LINE : GL_FILL);
             if(this->isRenderEnable()) {
                 this->_meshParticle.draw(this->_particles.size());
             }
+            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
             pg::error::OpenGLError::check();
 
diff --git a/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.hpp b/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.hpp
index 11ee44f..4fd1a63 100644
--- a/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.hpp
+++ b/ParticleGenerator/src/Scene/Scenes/MeshGeneratorModel.hpp
@@ -6,6 +6,7 @@
 #include <memory>
 
 #include "../../Mesh/Mesh.hpp"
+#include "../../Mesh/Skybox.hpp"
 #include "../../Mesh/Billboard.hpp"
 #include "../../Renderer/Renderer.hpp"
 #include "../../Particle/generator/PhysicsGenerator.hpp"
@@ -21,6 +22,7 @@ namespace pg::scene {
         private:
             Mesh _mesh;
             Program _meshProgram;
+            SkyBox _skybox;
             glm::vec3 _meshPosition;
             glm::vec3 _meshRotation;
 
diff --git a/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp b/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp
index cc920a0..bd724d0 100644
--- a/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp
+++ b/ParticleGenerator/src/Scene/Scenes/MultyPath.cpp
@@ -23,6 +23,15 @@ namespace pg::scene {
      }
 
     void MultyPath::initialize() {
+        this->_skybox.load({
+            "res/textures/skybox/snow/right.png",
+            "res/textures/skybox/snow/left.png",
+            "res/textures/skybox/snow/top.png",
+            "res/textures/skybox/snow/bottom.png",
+            "res/textures/skybox/snow/front.png",
+            "res/textures/skybox/snow/back.png"
+        }, Texture::AUTO, false);
+
         this->_billboard.initialize();
         this->_trajectory.initialize();
         if(!this->_program.usable()) {
@@ -88,6 +97,8 @@ namespace pg::scene {
         const glm::mat4 VIEW_MATRIX = camera.getViewMatrix();
         const glm::mat4 PROJECTION_MATRIX = camera.getViewFrustum().getProjectionMatrix();
 
+        this->_skybox.draw(camera);
+
         this->_trajectory.render(camera, current_time);
         pg::error::OpenGLError::check();
 
@@ -113,10 +124,12 @@ namespace pg::scene {
 
         pg::error::OpenGLError::check();
 
+        glPolygonMode(GL_FRONT_AND_BACK, this->isWireframeEnable() ? GL_LINE : GL_FILL);
         this->_texture.bind();
         if(this->isRenderEnable()) {
             this->_billboard.draw(this->_particles.size());
         }
+        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
         pg::error::OpenGLError::check();
     }
diff --git a/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp b/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp
index 37ec50d..0611464 100644
--- a/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp
+++ b/ParticleGenerator/src/Scene/Scenes/MultyPath.hpp
@@ -3,6 +3,7 @@
 #include "../Scene.hpp"
 
 #include "../../Renderer/Renderer.hpp"
+#include "../../Mesh/Skybox.hpp"
 #include "../../Particle/generator/PathMultyGenerator.hpp"
 #include "../../Mesh/Billboard.hpp"
 #include "TrajectoryMulty.hpp"
@@ -12,6 +13,7 @@
 namespace pg::scene {
     class MultyPath : public SceneParticle {
         private:
+            SkyBox _skybox;
             GLuint _ubo;
             Program _program;
             Billboard _billboard;
diff --git a/ParticleGenerator/src/Scene/Scenes/Path.cpp b/ParticleGenerator/src/Scene/Scenes/Path.cpp
index 26d7798..015c7f7 100644
--- a/ParticleGenerator/src/Scene/Scenes/Path.cpp
+++ b/ParticleGenerator/src/Scene/Scenes/Path.cpp
@@ -10,7 +10,7 @@ namespace pg::scene {
      _program(),
      _texture(),
      _generator(generator, ctrlpoint),
-     _trajectory(&this->_generator),
+     _trajectory(&this->_generator, 0.01),
      _color(1.f),
      _interface(this, &this->_generator, &this->_trajectory) {}
 
@@ -104,10 +104,12 @@ namespace pg::scene {
 
         pg::error::OpenGLError::check();
 
+        glPolygonMode(GL_FRONT_AND_BACK, this->isWireframeEnable() ? GL_LINE : GL_FILL);
         this->_texture.bind();
         if(this->isRenderEnable()) {
             this->_billboard.draw(this->_particles.size());
         }
+        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
         pg::error::OpenGLError::check();
     }
diff --git a/ParticleGenerator/src/Scene/Scenes/PathAnimated.cpp b/ParticleGenerator/src/Scene/Scenes/PathAnimated.cpp
index 0a4d599..0f659ca 100644
--- a/ParticleGenerator/src/Scene/Scenes/PathAnimated.cpp
+++ b/ParticleGenerator/src/Scene/Scenes/PathAnimated.cpp
@@ -130,10 +130,12 @@ namespace pg::scene {
 
         pg::error::OpenGLError::check();
 
+        glPolygonMode(GL_FRONT_AND_BACK, this->isWireframeEnable() ? GL_LINE : GL_FILL);
         this->_texture.bind();
         if(this->isRenderEnable()) {
             this->_mesh.draw(this->_particles.size());
         }
+        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
         pg::error::OpenGLError::check();
         glDisable(GL_DEPTH_TEST);
diff --git a/ParticleGenerator/src/Scene/Scenes/PathPregenerated.cpp b/ParticleGenerator/src/Scene/Scenes/PathPregenerated.cpp
index f1c4c2e..e650136 100644
--- a/ParticleGenerator/src/Scene/Scenes/PathPregenerated.cpp
+++ b/ParticleGenerator/src/Scene/Scenes/PathPregenerated.cpp
@@ -104,9 +104,11 @@ namespace pg::scene {
         pg::error::OpenGLError::check();
 
         this->_texture.bind();
+        glPolygonMode(GL_FRONT_AND_BACK, this->isWireframeEnable() ? GL_LINE : GL_FILL);
         if(this->isRenderEnable()) {
             this->_billboard.draw(this->_particles.size());
         }
+        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
         pg::error::OpenGLError::check();
     }
diff --git a/ParticleGenerator/src/Scene/Scenes/Physic.cpp b/ParticleGenerator/src/Scene/Scenes/Physic.cpp
index 132bfb3..d48f2b9 100644
--- a/ParticleGenerator/src/Scene/Scenes/Physic.cpp
+++ b/ParticleGenerator/src/Scene/Scenes/Physic.cpp
@@ -98,10 +98,11 @@ namespace pg::scene {
         this->_program.setUniform("uColor", this->_color);
 
         pg::error::OpenGLError::check();
-
+        glPolygonMode(GL_FRONT_AND_BACK, this->isWireframeEnable() ? GL_LINE : GL_FILL);
         if(this->isRenderEnable()) {
             this->_billboards.draw(this->_particles.size());
         }
+        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
         pg::error::OpenGLError::check();
     }
diff --git a/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp b/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp
index dfb35fd..a7c5503 100644
--- a/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp
+++ b/ParticleGenerator/src/Scene/Scenes/PhysicSprite.cpp
@@ -109,10 +109,11 @@ namespace pg::scene {
         this->_program.setUniform("uColor", this->_color);
 
         pg::error::OpenGLError::check();
-
+        glPolygonMode(GL_FRONT_AND_BACK, this->isWireframeEnable() ? GL_LINE : GL_FILL);
         if(this->isRenderEnable()) {
             this->_billboards.draw(this->_particles.size());
         }
+        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
         pg::error::OpenGLError::check();
     }
-- 
GitLab