diff --git a/ParticleGenerator/CMakeLists.txt b/ParticleGenerator/CMakeLists.txt index f6744e7911b79c3f95a2c903799dac00c3134402..857dd7793fa281face64e343a2a5561b0a2e628f 100644 --- a/ParticleGenerator/CMakeLists.txt +++ b/ParticleGenerator/CMakeLists.txt @@ -19,17 +19,18 @@ set(CMAKE_CXX_STANDARD ${CXX_STANDARD}) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -add_compile_definitions(RESSOURCE_PATH=${CMAKE_SOURCE_DIR}) +#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}) + #===================================== -# Options +# Options #===================================== option(USE_STATIC_DEPENDENCIES "Use dependencies as static libraries" OFF) option(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake") #===================================== -# Macros +# Macros #===================================== if(${USE_STATIC_DEPENDENCIES}) @@ -37,7 +38,7 @@ if(${USE_STATIC_DEPENDENCIES}) endif() #===================================== -# Source +# Source #===================================== set(LIB_DIRECTORY ${CMAKE_SOURCE_DIR}/external/lib) @@ -46,7 +47,7 @@ set(INCLUDE_DIRECTORY ${CMAKE_SOURCE_DIR}/external/include/) set(SOURCE_DIRECTORY ${CMAKE_SOURCE_DIR}/src/) #===================================== -# Build +# Build #===================================== project(${PROJECT_NAME} LANGUAGES CXX CUDA) @@ -59,6 +60,8 @@ add_subdirectory(${SOURCE_DIRECTORY}) target_compile_options(${CURRENT_TARGET} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-DUSE_STREAMS -gencode arch=compute_61,code=sm_61>) set_property(TARGET ${CURRENT_TARGET} PROPERTY CUDA_ARCHITECTURES OFF) +set_property(TARGET ${CURRENT_TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>) + target_link_directories(${CURRENT_TARGET} PRIVATE ${LIB_DIRECTORY}) diff --git a/ParticleGenerator/ParticleGenerator.exe b/ParticleGenerator/ParticleGenerator.exe new file mode 100644 index 0000000000000000000000000000000000000000..83625ba84b7897070af281d57e4f0e11a2fa5543 Binary files /dev/null and b/ParticleGenerator/ParticleGenerator.exe differ diff --git a/ParticleGenerator/ParticleGenerator.pdb b/ParticleGenerator/ParticleGenerator.pdb new file mode 100644 index 0000000000000000000000000000000000000000..c46357bcd341adbee94080b213a6fb6b9e799d75 Binary files /dev/null and b/ParticleGenerator/ParticleGenerator.pdb differ diff --git a/ParticleGenerator/res/config/imgui.ini b/ParticleGenerator/res/config/imgui.ini index 4c0d5234fc13d0bcca147f758e7aa4cb2d80efd8..76a4970f61a8ee84a544ac265e6464b976230717 100644 --- a/ParticleGenerator/res/config/imgui.ini +++ b/ParticleGenerator/res/config/imgui.ini @@ -23,7 +23,7 @@ Pos=10,4 Size=674,754 [Window][Particle Generator Settings] -Pos=38,2 +Pos=20,44 Size=523,732 [Window][Dear ImGui Demo] diff --git a/ParticleGenerator/res/models/magicalIndex/book.jpg b/ParticleGenerator/res/models/magicalIndex/book.jpg new file mode 100644 index 0000000000000000000000000000000000000000..bd5e87c7a09958bd84a053ad2be60258455eb053 Binary files /dev/null and b/ParticleGenerator/res/models/magicalIndex/book.jpg differ diff --git a/ParticleGenerator/res/models/magicalIndex/book.mtl b/ParticleGenerator/res/models/magicalIndex/book.mtl new file mode 100644 index 0000000000000000000000000000000000000000..ea72d6b903fd3f6441b845cb9e1478f29e5fa0b4 --- /dev/null +++ b/ParticleGenerator/res/models/magicalIndex/book.mtl @@ -0,0 +1,12 @@ +# Blender 4.1.1 MTL File: 'book.blend' +# www.blender.org + +newmtl Material.001 +Ns 0.000000 +Ka 1.000000 1.000000 1.000000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.000000 +d 1.000000 +illum 2 +map_Kd book.png diff --git a/ParticleGenerator/res/models/magicalIndex/book.obj b/ParticleGenerator/res/models/magicalIndex/book.obj new file mode 100644 index 0000000000000000000000000000000000000000..9dc41bb211ffa08eedf1a724df5a58e0da78a805 --- /dev/null +++ b/ParticleGenerator/res/models/magicalIndex/book.obj @@ -0,0 +1,56 @@ +# Blender 4.1.1 +# www.blender.org +#mtllib book.mtl +o Cube +v 1.000000 0.112074 -0.616080 +v 0.996224 -0.133569 -0.617124 +v 1.000000 0.112074 0.616042 +v 1.000000 -0.131600 0.616042 +v -1.000000 0.112074 -0.616080 +v -1.000000 -0.131600 -0.616080 +v -1.000000 0.112074 0.616042 +v -1.000000 -0.131600 0.616042 +vn -0.0000 1.0000 -0.0000 +vn -0.0000 -0.0000 1.0000 +vn -1.0000 -0.0000 -0.0000 +vn -0.0010 -1.0000 -0.0000 +vn 0.9999 -0.0154 -0.0030 +vn -0.0005 -0.0000 -1.0000 +vn -0.0000 -1.0000 0.0016 +vn 1.0000 -0.0000 -0.0000 +vn -0.0000 0.0042 -1.0000 +vt 0.831135 1.000000 +vt -0.000000 0.529971 +vt 0.831135 0.530923 +vt 1.000000 0.530926 +vt 0.833984 1.000000 +vt 0.833984 0.530926 +vt 0.831135 0.060894 +vt -0.000000 -0.000000 +vt 0.831135 0.000000 +vt -0.002323 0.061432 +vt 0.833457 0.529434 +vt 0.002328 0.530506 +vt 0.831135 0.060945 +vt 0.000000 0.060894 +vt 1.000000 0.060896 +vt 0.831055 0.530029 +vt 0.831055 0.060896 +vt -0.000000 1.000000 +vt 1.000000 1.000000 +vt 0.828807 0.060360 +vt 1.000000 0.530029 +s 0 +usemtl Material.001 +f 5/1/1 3/2/1 1/3/1 +f 3/4/2 8/5/2 4/6/2 +f 7/7/3 6/8/3 8/9/3 +f 2/10/4 8/11/4 6/12/4 +f 1/8/5 4/13/5 2/14/5 +f 5/15/6 2/16/6 6/17/6 +f 5/1/1 7/18/1 3/2/1 +f 3/4/2 7/19/2 8/5/2 +f 7/7/3 5/14/3 6/8/3 +f 2/10/7 4/20/7 8/11/7 +f 1/8/8 3/9/8 4/13/8 +f 5/15/9 1/21/9 2/16/9 diff --git a/ParticleGenerator/res/models/magicalIndex/book.png b/ParticleGenerator/res/models/magicalIndex/book.png new file mode 100644 index 0000000000000000000000000000000000000000..a7fd18d9dffafbeb4c2b16d0821b435b1828d824 Binary files /dev/null and b/ParticleGenerator/res/models/magicalIndex/book.png differ diff --git a/ParticleGenerator/res/models/magicalIndex/book_old.png b/ParticleGenerator/res/models/magicalIndex/book_old.png new file mode 100644 index 0000000000000000000000000000000000000000..cedcb8826c6fa74e09867eb50f774f3509ea4f38 Binary files /dev/null and b/ParticleGenerator/res/models/magicalIndex/book_old.png differ diff --git a/ParticleGenerator/res/shaders/scene/Phong-Fat.vert b/ParticleGenerator/res/shaders/scene/Phong-Fat.vert new file mode 100644 index 0000000000000000000000000000000000000000..1df49fcc73797d120260979e13ebc05876ca1671 --- /dev/null +++ b/ParticleGenerator/res/shaders/scene/Phong-Fat.vert @@ -0,0 +1,23 @@ +#version 330 core +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNormal; +layout (location = 2) in vec2 aTexture; + +out vec3 zFramPosition; +out vec3 zNormal; +out vec2 zTexture; + +uniform mat4 uView; +uniform mat4 uProj; + +layout(std140) uniform uModels_t { + mat4 models[1024]; +}; + +void main() { + zFramPosition = vec3(models[gl_InstanceID] * vec4(aPos, 1.0)); + zNormal = mat3(transpose(inverse(models[gl_InstanceID]))) * aNormal; + zTexture = aTexture; + + gl_Position = uProj* uView * vec4(zFramPosition, 1.0); +} \ No newline at end of file diff --git a/ParticleGenerator/res/shaders/scene/Phong.vert b/ParticleGenerator/res/shaders/scene/Phong.vert index bdc0451f169023352e1c3cbb5f1452bdd3863a90..40c3d7ea5f48ae150fea5853115cdb610299cba1 100644 --- a/ParticleGenerator/res/shaders/scene/Phong.vert +++ b/ParticleGenerator/res/shaders/scene/Phong.vert @@ -7,16 +7,13 @@ out vec3 zFramPosition; out vec3 zNormal; out vec2 zTexture; -layout(std140) uniform uModels_t { - mat4 models[1024]; -}; - uniform mat4 uView; uniform mat4 uProj; +uniform mat4 uModel; void main() { - zFramPosition = vec3(models[gl_InstanceID] * vec4(aPos, 1.0)); - zNormal = mat3(transpose(inverse(models[gl_InstanceID]))) * aNormal; + zFramPosition = vec3(uModel * vec4(aPos, 1.0)); + zNormal = mat3(transpose(inverse(uModel))) * aNormal; zTexture = aTexture; gl_Position = uProj* uView * vec4(zFramPosition, 1.0); diff --git a/ParticleGenerator/res/textures/skybox/school/back.png b/ParticleGenerator/res/textures/skybox/school/back.png deleted file mode 100644 index d4ad2a94b904036cdcf80ff414560d6213371233..0000000000000000000000000000000000000000 Binary files a/ParticleGenerator/res/textures/skybox/school/back.png and /dev/null differ diff --git a/ParticleGenerator/res/textures/skybox/school/bottom.png b/ParticleGenerator/res/textures/skybox/school/bottom.png deleted file mode 100644 index b274a28a57b343c86c86d6628294c2e25079c8c6..0000000000000000000000000000000000000000 Binary files a/ParticleGenerator/res/textures/skybox/school/bottom.png and /dev/null differ diff --git a/ParticleGenerator/res/textures/skybox/school/front.png b/ParticleGenerator/res/textures/skybox/school/front.png deleted file mode 100644 index 743ac09393245d4f487e2e69f966e44d8d529934..0000000000000000000000000000000000000000 Binary files a/ParticleGenerator/res/textures/skybox/school/front.png and /dev/null differ diff --git a/ParticleGenerator/res/textures/skybox/school/left.png b/ParticleGenerator/res/textures/skybox/school/left.png deleted file mode 100644 index d068d25a012a9d76410161245b383a40a2325598..0000000000000000000000000000000000000000 Binary files a/ParticleGenerator/res/textures/skybox/school/left.png and /dev/null differ diff --git a/ParticleGenerator/res/textures/skybox/school/right.png b/ParticleGenerator/res/textures/skybox/school/right.png deleted file mode 100644 index c3f183ce4aaf5c1acaa8d8d70391e9ff42cf1278..0000000000000000000000000000000000000000 Binary files a/ParticleGenerator/res/textures/skybox/school/right.png and /dev/null differ diff --git a/ParticleGenerator/res/textures/skybox/school/top.png b/ParticleGenerator/res/textures/skybox/school/top.png deleted file mode 100644 index e77d254fcc0b5a039cbb80f8a122f91324d1a41f..0000000000000000000000000000000000000000 Binary files a/ParticleGenerator/res/textures/skybox/school/top.png and /dev/null differ diff --git a/ParticleGenerator/res/textures/skybox/sky/back.png b/ParticleGenerator/res/textures/skybox/sky/back.png new file mode 100644 index 0000000000000000000000000000000000000000..fc3b663eaf5af759f57ef88781044e27d3fc8718 Binary files /dev/null and b/ParticleGenerator/res/textures/skybox/sky/back.png differ diff --git a/ParticleGenerator/res/textures/skybox/sky/bottom.png b/ParticleGenerator/res/textures/skybox/sky/bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..4a7283229c4c4426420face9189b2de551da5fbf Binary files /dev/null and b/ParticleGenerator/res/textures/skybox/sky/bottom.png differ diff --git a/ParticleGenerator/res/textures/skybox/sky/front.png b/ParticleGenerator/res/textures/skybox/sky/front.png new file mode 100644 index 0000000000000000000000000000000000000000..94989f7b3b11256a4ab8e7567bfed8925bed17b3 Binary files /dev/null and b/ParticleGenerator/res/textures/skybox/sky/front.png differ diff --git a/ParticleGenerator/res/textures/skybox/sky/left.png b/ParticleGenerator/res/textures/skybox/sky/left.png new file mode 100644 index 0000000000000000000000000000000000000000..ad4a6f1a1062692466f0edd2fd724b5dca9196c3 Binary files /dev/null and b/ParticleGenerator/res/textures/skybox/sky/left.png differ diff --git a/ParticleGenerator/res/textures/skybox/sky/right.png b/ParticleGenerator/res/textures/skybox/sky/right.png new file mode 100644 index 0000000000000000000000000000000000000000..7d4924cfc07010e4934bd66699316c7fa9e096af Binary files /dev/null and b/ParticleGenerator/res/textures/skybox/sky/right.png differ diff --git a/ParticleGenerator/res/textures/skybox/sky/top.png b/ParticleGenerator/res/textures/skybox/sky/top.png new file mode 100644 index 0000000000000000000000000000000000000000..dc72b68e5e3195e79007960c740ed3e5614c9392 Binary files /dev/null and b/ParticleGenerator/res/textures/skybox/sky/top.png differ diff --git a/ParticleGenerator/src/Mesh/Skybox.hpp b/ParticleGenerator/src/Mesh/Skybox.hpp index 8307d0e5542b5f6242c87a654d4825dcbb47d31d..888ec04bcc133e2e2751a386db094383ae7ea413 100644 --- a/ParticleGenerator/src/Mesh/Skybox.hpp +++ b/ParticleGenerator/src/Mesh/Skybox.hpp @@ -23,7 +23,7 @@ namespace pg { inline const CubemapMaterial & material() const {return this->_material;} - void load(const std::array<std::string, 6> & rltbfb, Texture::Format = Texture::Format::RGBA, bool = true); + void load(const std::array<std::string, 6> & rltbfb, Texture::Format = Texture::Format::AUTO, bool = true); void draw(const Camera &) const; static std::vector<float> SkyboxGeometry(); diff --git a/ParticleGenerator/src/Renderer/Texture/CubemapMaterial.cpp b/ParticleGenerator/src/Renderer/Texture/CubemapMaterial.cpp index b9f875823a1faab0e2660a13628abd7f6edcd148..e3ad1a183d804f09cd1f9d3dc1d78186b691fdb9 100644 --- a/ParticleGenerator/src/Renderer/Texture/CubemapMaterial.cpp +++ b/ParticleGenerator/src/Renderer/Texture/CubemapMaterial.cpp @@ -3,6 +3,8 @@ #include <stb/image/stb_image.h> #include <stdexcept> +#include "../Error/OpenGLError.hpp" + namespace pg { CubemapMaterial::CubemapMaterial(GLuint slot) : Texture(slot, GL_TEXTURE_CUBE_MAP) { @@ -23,10 +25,19 @@ namespace pg { } data = stbi_load(paths.at(i).c_str(), &width, &height, &nrComponents, 0); + GLuint format; + switch (nrComponents) { + case 3: + format = Texture::RGB; + break; + + case 4: + format = Texture::RGBA; + break; + } if(data) { - - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, format, GL_UNSIGNED_BYTE, data); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data); } else { throw std::runtime_error(std::string("Error when loading : ").append(paths[i])); @@ -35,6 +46,8 @@ namespace pg { this->_ressources.push_back(std::filesystem::path(paths[i])); } + error::OpenGLError::check(); + this->setSmoothing(true); this->setWraping(Wraping::CLAMP_TO_EDGE, Axis::S | Axis::T | Axis::R); } diff --git a/ParticleGenerator/src/Renderer/Texture/CubemapMaterial.hpp b/ParticleGenerator/src/Renderer/Texture/CubemapMaterial.hpp index 38665349ef67dc17824ceb21d246215b2c3bbaee..e19aad31787842afc7065351c5baaa5663c0ee7a 100644 --- a/ParticleGenerator/src/Renderer/Texture/CubemapMaterial.hpp +++ b/ParticleGenerator/src/Renderer/Texture/CubemapMaterial.hpp @@ -14,7 +14,7 @@ namespace pg { public: CubemapMaterial(GLuint = 0); - void load(const std::vector<std::string> &, Texture::Format = Format::RGBA, bool = true); + void load(const std::vector<std::string> &, Texture::Format = Format::AUTO, bool = true); inline const std::vector<std::filesystem::path> & getRessources() const {return this->_ressources;} }; diff --git a/ParticleGenerator/src/Renderer/Texture/Material.cpp b/ParticleGenerator/src/Renderer/Texture/Material.cpp index a21411119f0fb48a4e88ff4d598c48d77cdfc3b9..93fc0609ee0242c205d96c1a38f8037db99f54b1 100644 --- a/ParticleGenerator/src/Renderer/Texture/Material.cpp +++ b/ParticleGenerator/src/Renderer/Texture/Material.cpp @@ -5,6 +5,8 @@ #define STB_IMAGE_IMPLEMENTATION #include <stb/image/stb_image.h> +#include <iostream> + namespace pg { Material::Material() : Texture(0, GL_TEXTURE_2D), _ressource("./") { @@ -29,12 +31,25 @@ namespace pg { void Material::load(const std::string & path, Texture::Format format, bool invert) { this->_ressource = std::filesystem::canonical(path); if(std::filesystem::is_directory(this->_ressource) || !std::filesystem::exists(this->_ressource)) { - throw std::runtime_error("Cannot load ressource !"); + throw std::runtime_error(std::string("Cannot load ressource : ") + path); } int width, height, nrChannels; stbi_set_flip_vertically_on_load(invert); + unsigned char * data = stbi_load(path.c_str(), &width, &height, &nrChannels, 0); + if(format == Texture::AUTO) { + switch (nrChannels) { + case 3: + format = Texture::RGB; + break; + + case 4: + format = Texture::RGBA; + break; + } + } + this->store(width, height, data, format); stbi_image_free(data); } diff --git a/ParticleGenerator/src/Renderer/Texture/Material.hpp b/ParticleGenerator/src/Renderer/Texture/Material.hpp index 7e75b248bcd5f1261166080072eaaa52ac4d2175..6c7fb9bd23e5ad9dd1ed76db1819be333261a03a 100644 --- a/ParticleGenerator/src/Renderer/Texture/Material.hpp +++ b/ParticleGenerator/src/Renderer/Texture/Material.hpp @@ -14,11 +14,11 @@ namespace pg { Material(); Material(const Material &); Material(const std::string &, bool flip); - Material(const std::string &, Texture::Format = Texture::RGBA, bool = true); + Material(const std::string &, Texture::Format = Texture::AUTO, bool = true); Material operator=(const Material &) = delete; inline const std::filesystem::path & ressource() const {return this->_ressource;} - void load(const std::string &, Texture::Format = RGBA, bool = true); + void load(const std::string &, Texture::Format = AUTO, bool = true); }; } \ No newline at end of file diff --git a/ParticleGenerator/src/Renderer/Texture/Texture.cpp b/ParticleGenerator/src/Renderer/Texture/Texture.cpp index 90b56d4133461c32eba51be93ce920f79a5ba23a..e749de09ca43e1f6dff652a8bc86fa0fce43e34b 100644 --- a/ParticleGenerator/src/Renderer/Texture/Texture.cpp +++ b/ParticleGenerator/src/Renderer/Texture/Texture.cpp @@ -3,6 +3,8 @@ #include <exception> #include <iostream> +#include "../error/OpenGLError.hpp" + namespace pg { Texture::Texture(GLuint slot, GLuint type) : _id(0), _type(type), _slot(slot) { @@ -87,12 +89,15 @@ namespace pg { glDeleteTextures(1, &this->_id); glGenTextures(1, &this->_id); } - + glBindTexture(this->_type, this->_id); glTexImage2D(this->_type, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data); + error::OpenGLError::check(); + glGenerateMipmap(this->_type); this->setWraping(CLAMP_TO_BORDER, S | T ); this->setSmoothing(false); + } bool Texture::isValid() const { diff --git a/ParticleGenerator/src/Renderer/Texture/Texture.hpp b/ParticleGenerator/src/Renderer/Texture/Texture.hpp index 6e99c4e23165ee20145f77b71bfadd78fe128f92..293ec3cc6dac783fc274421dc0b78163100e8a9f 100644 --- a/ParticleGenerator/src/Renderer/Texture/Texture.hpp +++ b/ParticleGenerator/src/Renderer/Texture/Texture.hpp @@ -30,6 +30,7 @@ namespace pg { }; enum Format { + AUTO = 0, RGB = GL_RGB, BGR = GL_BGR, RGBA = GL_RGBA, @@ -53,7 +54,7 @@ namespace pg { void setWraping(Wraping, uint32_t = S | T); void setSmoothing(bool); - void store(GLsizei, GLsizei, const void *, GLuint = RGBA); + void store(GLsizei, GLsizei, const void *, GLuint = RGB); bool isValid() const; bool operator==(const Texture &) const; diff --git a/ParticleGenerator/src/Scene/Scenes/Grid.cpp b/ParticleGenerator/src/Scene/Scenes/Grid.cpp index dd347e6eee1439fcbfa5795a2a649fe3744ac294..6dba19dd27dead89ee8f1b75cfad4f639b3601fa 100644 --- a/ParticleGenerator/src/Scene/Scenes/Grid.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Grid.cpp @@ -1,13 +1,12 @@ #include "Grid.hpp" #include <glm/gtc/matrix_transform.hpp> -#include "../../System/Workspace.hpp" namespace pg::scene { Grid::Grid() : _gridMesh(), - _gridMaterial(WORKSPACE_PATH + "res/textures/grid.png"), + _gridMaterial("res/textures/grid.png"), _shader() { @@ -17,14 +16,14 @@ namespace pg::scene { if (!_gridMesh.isGenerated()) { - Model gridModel(WORKSPACE_PATH + "res/models/plane.obj"); + Model gridModel("res/models/plane.obj"); _gridMesh.generate(gridModel.getMeshGeometry().vertices, gridModel.getMeshGeometry().indices); } if (!_shader.usable()) { - Source vertexShaderSource(WORKSPACE_PATH + "res/shaders/scene/Grid.vert", Source::Categorie::VERTEX); - Source fragmentShaderSource(WORKSPACE_PATH + "/res/shaders/scene/Grid.frag", Source::Categorie::FRAGMENT); + Source vertexShaderSource("res/shaders/scene/Grid.vert", Source::Categorie::VERTEX); + Source fragmentShaderSource("/res/shaders/scene/Grid.frag", Source::Categorie::FRAGMENT); _shader << vertexShaderSource; _shader << fragmentShaderSource; diff --git a/ParticleGenerator/src/Scene/Scenes/MagicalIndex.cpp b/ParticleGenerator/src/Scene/Scenes/MagicalIndex.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ceab1cb6980cffa97afe5036ba1853ca39fe924e --- /dev/null +++ b/ParticleGenerator/src/Scene/Scenes/MagicalIndex.cpp @@ -0,0 +1,89 @@ +#include "MagicalIndex.hpp" + +#include "../../Mesh/Model.hpp" + +namespace pg::scene +{ + MagicalIndex::MagicalIndex() + : _skybox("res/shaders/system/Skybox.vert", "res/shaders/system/Skybox.frag") {} + + void MagicalIndex::initialize() + { + std::cout << "Mark_0" << std::endl; + if (!this->_book.isGenerated()) + { + Model meshBook("res/models/magicalIndex/book.obj"); + this->_book.generate(meshBook.getMeshGeometry().vertices, meshBook.getMeshGeometry().indices); + } + std::cout << "Mark_1" << std::endl; + + this->_bookMaterial.load("res/models/magicalIndex/book.png"); + error::OpenGLError::check(); + std::cout << "Mark_2" << std::endl; + + if (!this->_program.usable()) + { + Source vertexShaderSource("res/shaders/scene/Phong.vert", Source::Categorie::VERTEX); + Source fragmentShaderSource("res/shaders/scene/Phong.frag", Source::Categorie::FRAGMENT); + + this->_program << vertexShaderSource; + this->_program << fragmentShaderSource; + + this->_program.link(); + + vertexShaderSource.release(); + fragmentShaderSource.release(); + } + + error::OpenGLError::check(); + std::cout << "Mark_3" << std::endl; + + if (this->_skybox.material().isValid()) + { + this->_skybox.load( + { + "res/textures/skybox/sky/right.png", + "res/textures/skybox/sky/left.png", + "res/textures/skybox/sky/top.png", + "res/textures/skybox/sky/bottom.png", + "res/textures/skybox/sky/front.png", + "res/textures/skybox/sky/back.png", + }, + Texture::Format::AUTO, + false); + } + + error::OpenGLError::check(); + std::cout << "Mark_4" << std::endl; + } + + void MagicalIndex::update(double) + { + } + + void MagicalIndex::render(const Camera &camera, double current_time) + { + this->_skybox.material().bind(0); + this->_skybox.draw(camera); + + glEnable(GL_DEPTH_TEST); + this->_bookMaterial.bind(0); + + this->_program.use(); + this->_program.setUniform("uModel", glm::mat4(1.f)); + this->_program.setUniform("uView", camera.getViewMatrix()); + this->_program.setUniform("uProj", camera.getViewFrustum().getProjectionMatrix()); + + this->_program.setUniform("uSlot", 0); + this->_program.setUniform("uLightPosition", glm::vec3(0.f, 10.f, 0.f)); + this->_program.setUniform("uViewPosition", camera.getPosition()); + this->_program.setUniform("uColor", glm::vec3(1.f, 1.f, 1.f)); + + this->_book.draw(); + glDisable(GL_DEPTH_TEST); + } + + void MagicalIndex::destroy() + { + } +} \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/MagicalIndex.hpp b/ParticleGenerator/src/Scene/Scenes/MagicalIndex.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4b8a96d269ad94f328fbacb2efacea47f51afe59 --- /dev/null +++ b/ParticleGenerator/src/Scene/Scenes/MagicalIndex.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "Scene.hpp" + +#include "../../Renderer/Shader/Program.hpp" +#include "../../Renderer/Texture/Material.hpp" + +#include "../../Mesh/Mesh.hpp" +#include "../../Mesh/Skybox.hpp" +#include "../../Mesh/Billboard.hpp" + + +namespace pg::scene { + class MagicalIndex : public Scene { + private: + Mesh _book; + Material _bookMaterial; + SkyBox _skybox; + Program _program; + + public: + MagicalIndex(); + + virtual void initialize(); + virtual void update(double); + virtual void render(const Camera &, double); + virtual void destroy(); + + virtual inline std::string name() const {return "A Certain Magical Index Scene";}; + virtual inline Interface * interface() {return nullptr;}; + }; +} \ No newline at end of file diff --git a/ParticleGenerator/src/Scene/Scenes/Mesh.cpp b/ParticleGenerator/src/Scene/Scenes/Mesh.cpp index f15b791c0f9761ac677020171690f4a4724255aa..c06520ca309cec059b415bbbf948edeb965fef8d 100644 --- a/ParticleGenerator/src/Scene/Scenes/Mesh.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Mesh.cpp @@ -1,7 +1,6 @@ #include "Mesh.hpp" #include <glm/gtc/matrix_transform.hpp> -#include "../../System/Workspace.hpp" namespace pg::scene { @@ -15,7 +14,7 @@ namespace pg::scene _scale(1.f, 1.f, 1.f), _pathGenerator(generator, ctrlpoint), _physicGenerator(), - _skybox(WORKSPACE_PATH + "res/shaders/system/Skybox.vert", WORKSPACE_PATH + "res/shaders/system/Skybox.frag"), + _skybox("res/shaders/system/Skybox.vert", "res/shaders/system/Skybox.frag"), _interface(this, &this->_pathGenerator, &this->_physicGenerator), _useTexture(false), _pathActive(false), @@ -27,13 +26,13 @@ namespace pg::scene void Mesh::initialize() { if (!this->_mesh.isGenerated()) { - Model gridModel(WORKSPACE_PATH + "res/models/cube.obj"); + Model gridModel("res/models/cube.obj"); this->_mesh.generate(gridModel.getMeshGeometry().vertices, gridModel.getMeshGeometry().indices); } if(!this->_textureShader.usable()) { - Source vertexShaderSource(WORKSPACE_PATH + "res/shaders/scene/Phong.vert", Source::Categorie::VERTEX); - Source fragmentShaderSource(WORKSPACE_PATH + "res/shaders/scene/Phong.frag", Source::Categorie::FRAGMENT); + Source vertexShaderSource("res/shaders/scene/Phong-Fat.vert", Source::Categorie::VERTEX); + Source fragmentShaderSource("res/shaders/scene/Phong.frag", Source::Categorie::FRAGMENT); this->_textureShader << vertexShaderSource; this->_textureShader << fragmentShaderSource; @@ -45,8 +44,8 @@ namespace pg::scene } if(!this->_colorShader.usable()) { - Source vertexShaderSource(WORKSPACE_PATH + "res/shaders/scene/Color-Fat.vert", Source::Categorie::VERTEX); - Source fragmentShaderSource(WORKSPACE_PATH + "res/shaders/scene/Color.frag", Source::Categorie::FRAGMENT); + Source vertexShaderSource("res/shaders/scene/Color-Fat.vert", Source::Categorie::VERTEX); + Source fragmentShaderSource("res/shaders/scene/Color.frag", Source::Categorie::FRAGMENT); this->_colorShader << vertexShaderSource; this->_colorShader << fragmentShaderSource; @@ -60,12 +59,12 @@ namespace pg::scene if(this->_skybox.material().isValid()) { this->_skybox.load( { - WORKSPACE_PATH + "res/textures/skybox/default/right.png", - WORKSPACE_PATH + "res/textures/skybox/default/left.png", - WORKSPACE_PATH + "res/textures/skybox/default/top.png", - WORKSPACE_PATH + "res/textures/skybox/default/bottom.png", - WORKSPACE_PATH + "res/textures/skybox/default/front.png", - WORKSPACE_PATH + "res/textures/skybox/default/back.png", + "res/textures/skybox/default/right.png", + "res/textures/skybox/default/left.png", + "res/textures/skybox/default/top.png", + "res/textures/skybox/default/bottom.png", + "res/textures/skybox/default/front.png", + "res/textures/skybox/default/back.png", }, Texture::RGBA, false diff --git a/ParticleGenerator/src/Scene/Scenes/Path.cpp b/ParticleGenerator/src/Scene/Scenes/Path.cpp index acd22e44a44ad3f0829c1207037060c90d0c2aeb..fa55cb0a0076a10faa17cdcc7ed32f70aaef7e26 100644 --- a/ParticleGenerator/src/Scene/Scenes/Path.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Path.cpp @@ -3,8 +3,6 @@ #include <chrono> #include <glm/gtc/matrix_transform.hpp> -#include "../../System/Workspace.hpp" - namespace pg::scene { Path::Path(ct::CurveGenerator * generator, const ct::Curve & ctrlpoint) : _ubo(0), @@ -17,8 +15,8 @@ namespace pg::scene { void Path::initialize() { this->_billboard.initialize(); if(!this->_program.usable()) { - pg::Source vertices(WORKSPACE_PATH + "res/shaders/scene/Billboard.vert", pg::Source::Categorie::VERTEX); - pg::Source fragment(WORKSPACE_PATH + "res/shaders/scene/Billboard.frag", pg::Source::Categorie::FRAGMENT); + pg::Source vertices("res/shaders/scene/Billboard.vert", pg::Source::Categorie::VERTEX); + pg::Source fragment("res/shaders/scene/Billboard.frag", pg::Source::Categorie::FRAGMENT); this->_program << vertices; this->_program << fragment; @@ -40,7 +38,7 @@ namespace pg::scene { pg::error::OpenGLError::check(); - this->_texture.load(WORKSPACE_PATH + "res/textures/smoke1.png"); + this->_texture.load("res/textures/smoke1.png"); pg::error::OpenGLError::check(); diff --git a/ParticleGenerator/src/Scene/Scenes/Physic.cpp b/ParticleGenerator/src/Scene/Scenes/Physic.cpp index f35ea2d78c47926d25d7a91ae444e0e5b38e95a1..e1be3d0946f1271c22616cbf4d791395d835ac8b 100644 --- a/ParticleGenerator/src/Scene/Scenes/Physic.cpp +++ b/ParticleGenerator/src/Scene/Scenes/Physic.cpp @@ -3,8 +3,6 @@ #include <chrono> #include <glm/gtc/matrix_transform.hpp> -#include "../../System/Workspace.hpp" - namespace pg::scene { Physic::Physic() : _ubo(0), @@ -17,8 +15,8 @@ namespace pg::scene { void Physic::initialize() { this->_billboards.initialize(); if(!this->_program.usable()) { - pg::Source vertices(WORKSPACE_PATH + "res/shaders/scene/Billboard.vert", pg::Source::Categorie::VERTEX); - pg::Source fragment(WORKSPACE_PATH + "res/shaders/scene/Billboard.frag", pg::Source::Categorie::FRAGMENT); + pg::Source vertices("res/shaders/scene/Billboard.vert", pg::Source::Categorie::VERTEX); + pg::Source fragment("res/shaders/scene/Billboard.frag", pg::Source::Categorie::FRAGMENT); this->_program << vertices; this->_program << fragment; @@ -40,7 +38,7 @@ namespace pg::scene { pg::error::OpenGLError::check(); - this->_texture.load(WORKSPACE_PATH + "res/textures/smoke1.png"); + this->_texture.load("res/textures/smoke1.png"); pg::error::OpenGLError::check(); diff --git a/ParticleGenerator/src/System/Workspace.hpp b/ParticleGenerator/src/System/Workspace.hpp deleted file mode 100644 index 1b5bb3dd678bac88baeea0c744a532fe5feb6509..0000000000000000000000000000000000000000 --- a/ParticleGenerator/src/System/Workspace.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include <string> - -#ifndef RESSOURCE_PATH - #define RESSOURCE_PATH -#endif - -#define STRINGIFY(x) #x -#define TOSTRING(x) STRINGIFY(x) - -namespace pg { - static const std::string WORKSPACE_PATH = std::string(TOSTRING(RESSOURCE_PATH)) + "/"; - -} \ No newline at end of file diff --git a/ParticleGenerator/src/main.cpp b/ParticleGenerator/src/main.cpp index 044ac7cfea6969bc286bbe28a74a5d8725f5b7a1..348fd5856f4197ee2494a5ae771ec2d60cb6865e 100644 --- a/ParticleGenerator/src/main.cpp +++ b/ParticleGenerator/src/main.cpp @@ -3,12 +3,12 @@ #include "Renderer/Renderer.hpp" #include "System/Window.hpp" -#include "System/Workspace.hpp" #include "Scene/Manager.hpp" #include "Scene/Scenes/Grid.hpp" #include "Scene/Scenes/Physic.hpp" #include "Scene/Scenes/Path.hpp" #include "Scene/Scenes/Mesh.hpp" +#include "Scene/Scenes/MagicalIndex.hpp" #include "Interface/GlobalInterface.hpp" @@ -82,12 +82,16 @@ int main(int argc, const char * argv[]) { pg::scene::Physic physicScene; pg::scene::Path pathScene(&bezier, ctrlPoints); pg::scene::Mesh meshScene(&bezier, ctrlPoints); + pg::scene::MagicalIndex magicalIndex; pg::Manager manager(window, &physicScene); + manager.add(physicScene); manager.add(pathScene); manager.add(meshScene); + manager.add(magicalIndex); + pg::GlobalInterface interface(window, manager, "Particle Generator Settings"); while(window.isOpen()) {