diff --git a/assets/shaders/Image-Instanced-Animated.vert b/assets/shaders/Image-Instanced-Animated.vert new file mode 100644 index 0000000000000000000000000000000000000000..feb6172edd28255caa9ff8a942fb0d7e14d4f1fc --- /dev/null +++ b/assets/shaders/Image-Instanced-Animated.vert @@ -0,0 +1,20 @@ +#version 330 core +layout (location = 0) in vec2 aPos; +layout (location = 1) in vec2 aTex; + +uniform mat4 uProj; +uniform mat4 uView; +uniform mat4 uModel[128]; + +uniform float uTime; + +out vec2 Texture; + +float process(vec2 pos, mat4 model, float time, int id) { + return pos.y + sin(time + id * 0.01); +} + +void main() { + Texture = aTex; + gl_Position = uProj * uView * uModel[gl_InstanceID] * vec4(aPos.x, process(aPos, uModel[gl_InstanceID], uTime, gl_InstanceID), 0.0, 1.0); +} \ No newline at end of file diff --git a/assets/textures/Cube_Air.png b/assets/textures/Cube_Air.png new file mode 100644 index 0000000000000000000000000000000000000000..ed6b8e0766c45ad7800bcd2a972db9bd9ce8e979 Binary files /dev/null and b/assets/textures/Cube_Air.png differ diff --git a/assets/textures/Cube_Amber.png b/assets/textures/Cube_Amber.png deleted file mode 100644 index 2818dc1c2e2ce58ac8d1c13f1ea554e000ea450c..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Amber.png and /dev/null differ diff --git a/assets/textures/Cube_Blue.png b/assets/textures/Cube_Blue.png index 660ea2bcf6a491b02d8245636432892a96cac429..507f300138b6411b10e78bad4cc2a83b3aaba7da 100644 Binary files a/assets/textures/Cube_Blue.png and b/assets/textures/Cube_Blue.png differ diff --git a/assets/textures/Cube_Brown.png b/assets/textures/Cube_Brown.png deleted file mode 100644 index 6625a70ebf229d0bd2531ebd3723c97dcac377d0..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Brown.png and /dev/null differ diff --git a/assets/textures/Cube_Cyan.png b/assets/textures/Cube_Cyan.png index e154c1b9291be5f26b3735e77279271177ba376a..13773ab71faba09930bdb840951eaa60571b0f9d 100644 Binary files a/assets/textures/Cube_Cyan.png and b/assets/textures/Cube_Cyan.png differ diff --git a/assets/textures/Cube_Dark_Green.png b/assets/textures/Cube_Dark_Green.png deleted file mode 100644 index e2e446677e0be7233a32d5f4436d2b1b7df8d14d..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Dark_Green.png and /dev/null differ diff --git a/assets/textures/Cube_Grass.png b/assets/textures/Cube_Grass.png index bf967e698b61604ff8428348c9ad2d9d3b0e8538..cdf1c247f553a7bac65b41a60a90ba387e72e327 100644 Binary files a/assets/textures/Cube_Grass.png and b/assets/textures/Cube_Grass.png differ diff --git a/assets/textures/Cube_Gray.png b/assets/textures/Cube_Gray.png index a2057bc9e04b33cb9e494f72a35d2693da1e0047..d1f106c214c46328ab91ca74b87a8561286239bb 100644 Binary files a/assets/textures/Cube_Gray.png and b/assets/textures/Cube_Gray.png differ diff --git a/assets/textures/Cube_Grayy.png b/assets/textures/Cube_Grayy.png deleted file mode 100644 index 405cb6f9309a3775a9d9cfc8137688ac33152514..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Grayy.png and /dev/null differ diff --git a/assets/textures/Cube_Green.png b/assets/textures/Cube_Green.png index e863145c801b80978785b3f2a1949f24fc31f2e4..fcf9d95475e3f448c86c6bf73678eee864e84000 100644 Binary files a/assets/textures/Cube_Green.png and b/assets/textures/Cube_Green.png differ diff --git a/assets/textures/Cube_Greeny.png b/assets/textures/Cube_Greeny.png deleted file mode 100644 index 7adbb641868ecf1fe99512d0dda3302e63b14abd..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Greeny.png and /dev/null differ diff --git a/assets/textures/Cube_Inverted.png b/assets/textures/Cube_Inverted.png deleted file mode 100644 index c88966e2a81981d7e9ad95375909d70e89289569..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Inverted.png and /dev/null differ diff --git a/assets/textures/Cube_Inverted_2.png b/assets/textures/Cube_Inverted_2.png deleted file mode 100644 index 8da98f7caf655f6813524717d75e8f8ca23d257c..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Inverted_2.png and /dev/null differ diff --git a/assets/textures/Cube_Lava.png b/assets/textures/Cube_Lava.png new file mode 100644 index 0000000000000000000000000000000000000000..064c841716d1f8629cd93615e4bc81c8a6e7749e Binary files /dev/null and b/assets/textures/Cube_Lava.png differ diff --git a/assets/textures/Cube_Magenta.png b/assets/textures/Cube_Magenta.png deleted file mode 100644 index d6c445d966448805ceb5301a6b7701676c0e31e9..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Magenta.png and /dev/null differ diff --git a/assets/textures/Cube_Orange.png b/assets/textures/Cube_Orange.png index af4c2ecb3a372c602cd3a570464906733dbd230a..3507d1817b1ce103382da1a2c0fc64aa0d84ae0b 100644 Binary files a/assets/textures/Cube_Orange.png and b/assets/textures/Cube_Orange.png differ diff --git a/assets/textures/Cube_Pink.png b/assets/textures/Cube_Pink.png index 5a7ea7ef1b519bb8751293c66699de4ec76c6155..ba27564cbc49fd9b80963fe86a3e7b60035718d5 100644 Binary files a/assets/textures/Cube_Pink.png and b/assets/textures/Cube_Pink.png differ diff --git a/assets/textures/Cube_Purple.png b/assets/textures/Cube_Purple.png index 10e017c1f432c1d9eab0a939a311bba880ee7b30..ee44d1c36dc3d41ddcc29ae14f87b7a0ac54346e 100644 Binary files a/assets/textures/Cube_Purple.png and b/assets/textures/Cube_Purple.png differ diff --git a/assets/textures/Cube_Red.png b/assets/textures/Cube_Red.png index fa5264076cdce558b91dc109cc21cc587bbc3495..0a74973acf3f347737254a42611fadb532695d1f 100644 Binary files a/assets/textures/Cube_Red.png and b/assets/textures/Cube_Red.png differ diff --git a/assets/textures/Cube_Redy.png b/assets/textures/Cube_Redy.png deleted file mode 100644 index a2e2022e42869b30ec3a07e20a981daac7ada6a2..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Redy.png and /dev/null differ diff --git a/assets/textures/Cube_Saumon.png b/assets/textures/Cube_Saumon.png deleted file mode 100644 index e370b7ab8ddd84fbdf284149415e35ea06cdf66b..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Saumon.png and /dev/null differ diff --git a/assets/textures/Cube_Sepia.png b/assets/textures/Cube_Sepia.png new file mode 100644 index 0000000000000000000000000000000000000000..6c1088662450d67d9c75dcffb3b13b81bd70e372 Binary files /dev/null and b/assets/textures/Cube_Sepia.png differ diff --git a/assets/textures/Cube_Void.png b/assets/textures/Cube_Void.png new file mode 100644 index 0000000000000000000000000000000000000000..9743f77ea12dda6388eb70707aa02019ad0a7f89 Binary files /dev/null and b/assets/textures/Cube_Void.png differ diff --git a/assets/textures/Cube_Yellow.png b/assets/textures/Cube_Yellow.png index 0f055da0c20cc1b2f3da0d12ef895ab2402b308e..0101f31b955bc6fac43581e556bbeea94b9f03a9 100644 Binary files a/assets/textures/Cube_Yellow.png and b/assets/textures/Cube_Yellow.png differ diff --git a/assets/textures/Cube_Yellowy.png b/assets/textures/Cube_Yellowy.png deleted file mode 100644 index 0b29e005f793fc7f11c13b4b1c35904720274cac..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Yellowy.png and /dev/null differ diff --git a/source/engine/graphics/back/textures/Texture.cpp b/source/engine/graphics/back/textures/Texture.cpp index e913a049b849777323b098d501b06af5070c13d8..ccc5e95ed5dc8353a7c1e1e6acd6f4fb7ed317f3 100644 --- a/source/engine/graphics/back/textures/Texture.cpp +++ b/source/engine/graphics/back/textures/Texture.cpp @@ -17,6 +17,13 @@ namespace megu { Texture::Texture(const Texture & texture) : _id(texture._id), _type(texture._type), _slot(texture._slot) {} + Texture & Texture::operator=(const Texture & texture) { + this->_id = texture._id; + this->_slot = texture._slot; + this->_type = texture._type; + return *this; + } + Texture::~Texture() { glDeleteTextures(1, &this->_id); } diff --git a/source/engine/graphics/back/textures/Texture.hpp b/source/engine/graphics/back/textures/Texture.hpp index aeb75f89bb5035327c64ceec1708fa0d16fc002c..39345b128448bf12f63f637969b3b3cd207fe451 100644 --- a/source/engine/graphics/back/textures/Texture.hpp +++ b/source/engine/graphics/back/textures/Texture.hpp @@ -11,7 +11,7 @@ namespace megu { Texture(GLuint = 0, GLuint = GL_TEXTURE_2D); Texture(const std::filesystem::path &, GLuint = 0); Texture(const Texture &); - Texture & operator=(const Texture &) = delete; + Texture & operator=(const Texture &); ~Texture(); enum Wraping { diff --git a/source/engine/graphics/back/textures/TextureBuffer.hpp b/source/engine/graphics/back/textures/TextureBuffer.hpp index 489e72e48042aeab55e49f180f662f76bcddd312..4bdde6a2d24afca6d10b707992a2a64bd7ec88f1 100644 --- a/source/engine/graphics/back/textures/TextureBuffer.hpp +++ b/source/engine/graphics/back/textures/TextureBuffer.hpp @@ -9,7 +9,7 @@ namespace megu { public: TextureBuffer(); TextureBuffer(GLuint, GLuint, GLubyte *, GLenum); - TextureBuffer(const std::filesystem::path &, bool = false); + TextureBuffer(const std::filesystem::path &, bool = true); TextureBuffer(const TextureBuffer &); TextureBuffer & operator=(const TextureBuffer & src); ~TextureBuffer() = default; diff --git a/source/engine/graphics/front/group/DrawGroup.hpp b/source/engine/graphics/front/group/DrawGroup.hpp index d9a485553feab5e4de392008b34664fb409a0d1f..3c57018818bfa00ae73294798a8928bbb33b1021 100644 --- a/source/engine/graphics/front/group/DrawGroup.hpp +++ b/source/engine/graphics/front/group/DrawGroup.hpp @@ -1,10 +1,11 @@ #pragma once #include <engine/graphics/back/cameras/Camera.hpp> +#include <engine/io/Window.hpp> namespace megu { class DrawGroup { public: - virtual void draw(const Camera &) const = 0; + virtual void draw(const Window &, const Camera &) const = 0; }; } \ No newline at end of file diff --git a/source/engine/graphics/front/group/ImageGroup.cpp b/source/engine/graphics/front/group/ImageGroup.cpp index 5239d8e8c0eb10b79fbf2929e614d8c466a96678..d40ae5f39b8bd114b8f0b6b872ce4ccc8abb681f 100644 --- a/source/engine/graphics/front/group/ImageGroup.cpp +++ b/source/engine/graphics/front/group/ImageGroup.cpp @@ -32,18 +32,18 @@ namespace megu { } } - void ImageGroup::draw(const Camera & camera) const { + void ImageGroup::draw(const Window & window, const Camera & camera) const { this->_vao.bind(); this->_program.use(); - std::map<std::reference_wrapper<const Texture>, std::vector<std::reference_wrapper<const glm::mat4>>> data; + std::map<std::reference_wrapper<const Texture>, std::vector<glm::mat4>, std::greater<megu::Texture>> data; for(auto & image : this->_images) { data[image.get().texture()].push_back(image.get().transformation().model()); } - + for(auto &[texture, models] : data) { - texture.get().bind(); + texture.get().bind(0); this->_program.setUniform("uProj", camera.projection()); this->_program.setUniform("uView", camera.view()); diff --git a/source/engine/graphics/front/group/ImageGroup.hpp b/source/engine/graphics/front/group/ImageGroup.hpp index 8bad28b9b4526814241590b4149ac26d6f46920d..ed674ee1b0c496826ba2da7734a4eb16474ac16e 100644 --- a/source/engine/graphics/front/group/ImageGroup.hpp +++ b/source/engine/graphics/front/group/ImageGroup.hpp @@ -20,7 +20,7 @@ namespace megu { ImageGroup(); ~ImageGroup() = default; - void draw(const Camera & camera) const override; + void draw(const Window &, const Camera &) const override; void add(const Image &); void update(); diff --git a/source/engine/graphics/front/group/isometric_sorter.cpp b/source/engine/graphics/front/group/isometric_sorter.cpp index b1eb9261b340f9b3c602c7c764ff2054263f031c..94ae8d0dd4ed067ddd8e2656f0c77f05d68d028b 100644 --- a/source/engine/graphics/front/group/isometric_sorter.cpp +++ b/source/engine/graphics/front/group/isometric_sorter.cpp @@ -9,7 +9,7 @@ namespace megu { } if(img1.transformation().y() != img2.transformation().y()) { - return img1.transformation().y() < img2.transformation().y(); + return img1.transformation().y() > img2.transformation().y(); } if(img1.transformation().x() != img2.transformation().x()) { diff --git a/source/engine/graphics/front/object/Image.cpp b/source/engine/graphics/front/object/Image.cpp index dce4a4269d6ffcbb1d3e667dcc10dd4dd08f05d0..aa830c870cd38453cc03ffc0a60ac7d02450697b 100644 --- a/source/engine/graphics/front/object/Image.cpp +++ b/source/engine/graphics/front/object/Image.cpp @@ -14,9 +14,11 @@ namespace megu { } Image::Image(const Texture & texture) - : _texture(texture), + : _texture(), _geometry(), - _transformation() {} + _transformation() { + this->load(texture); + } Image::Image(const Image & src) : _texture(src._texture), @@ -34,4 +36,9 @@ namespace megu { this->setSize(static_cast<float>(buffer.width()), static_cast<float>(buffer.height())); this->_texture.store(buffer); } + + void Image::load(const Texture & texture) { + this->setSize(static_cast<float>(texture.width()), static_cast<float>(texture.height())); + this->_texture = texture; + } } \ No newline at end of file diff --git a/source/engine/graphics/front/object/Image.hpp b/source/engine/graphics/front/object/Image.hpp index 485d7036da82d3fb7a7f399a7bdd9cf3332b174a..ea098a320bbf9dcf16764fca034e5ee0b7bece00 100644 --- a/source/engine/graphics/front/object/Image.hpp +++ b/source/engine/graphics/front/object/Image.hpp @@ -26,8 +26,9 @@ namespace megu { inline void setRotation(float a) {this->_transformation.setRotation(a, Transformable::Axis::Z);} inline void setLayer(float l) {this->_transformation.setZ(l);} - void load(const std::filesystem::path &, bool = true); + void load(const std::filesystem::path &, bool = false); void load(const TextureBuffer &); + void load(const Texture &); inline const Texture & texture() const {return this->_texture;} inline const Quads & geometry() const {return this->_geometry;} diff --git a/source/main.cpp b/source/main.cpp index 853f72d3bd17605040b345d57348ea059d7e93e3..ecd068c0726151c576b2802c2dc6caa12c514ac5 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -50,29 +50,16 @@ int main(int argc, const char * argv[]) { //? Image std::vector<int> map = { - 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, - 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, - 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, - 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, - 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, - 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, - 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, - 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, - 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, - 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, - }; - - std::vector<std::string> textures = { - "assets/textures/Cube_Red.png", - "assets/textures/Cube_Blue.png", - "assets/textures/Cube_Green.png", - "assets/textures/Cube_Cyan.png", - "assets/textures/Cube_Pink.png", - "assets/textures/Cube_Yellow.png", - "assets/textures/Cube_Magenta.png", - "assets/textures/Cube_Purple.png", - "assets/textures/Cube_Gray.png", - "assets/textures/Cube_Orange.png" + 0, 0, 0, 0, 1, 2, 3, 0, 0, 3, + 0, 0, 0, 2, 0, 3, 0, 0, 3, 1, + 0, 0, 1, 3, 3, 0, 0, 0, 2, 2, + 0, 2, 1, 0, 0, 1, 0, 2, 0, 0, + 2, 1, 3, 1, 0, 0, 3, 0, 1, 0, + 1, 3, 0, 2, 3, 0, 0, 1, 0, 0, + 0, 1, 0, 0, 1, 2, 3, 1, 0, 0, + 0, 0, 0, 0, 2, 0, 1, 0, 1, 0, + 0, 0, 0, 2, 0, 0, 0, 1, 3, 0, + 0, 0, 3, 1, 2, 0, 0, 0, 2, 3, }; size_t x = 0; @@ -80,13 +67,16 @@ int main(int argc, const char * argv[]) { std::vector<std::unique_ptr<megu::Image>> images; + megu::Texture texture; + texture.store(megu::TextureBuffer("assets/textures/Cube_Grass.png")); + for(auto id : map) { if(x == 10) { x = 0; ++y; } - images.push_back(std::make_unique<megu::Image>(textures.at(3))); + images.push_back(std::make_unique<megu::Image>(texture)); glm::vec2 pos = to_screen_coordinate({x, y}, 32.f, 32.f); images.back()->setPosition(pos.x + 160, pos.y); @@ -106,7 +96,7 @@ int main(int argc, const char * argv[]) { ImGui_ImplGlfw_InitForOpenGL(window.ptr(), true); //? Render Loop - glClearColor(NORMALIZE(110), NORMALIZE(110), NORMALIZE(255), 0.f); + glClearColor(1.f, 1.f, 1.f, 1.f); double lastTime = glfwGetTime(); int nbFrames = 0; @@ -130,9 +120,9 @@ int main(int argc, const char * argv[]) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); window.pollEvents(); - group.draw(view); + group.draw(window, view); - ImGui_ImplOpenGL3_NewFrame(); + /*ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); @@ -184,7 +174,7 @@ int main(int argc, const char * argv[]) { ImGui::End(); ImGui::Render(); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());*/ window.swapBuffers(); }