From d1f0d5c7b0380267346ca483937fdebb85633ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr> Date: Fri, 3 Jan 2025 18:09:40 +0100 Subject: [PATCH] Add tile --- .gitignore | 4 +- assets/shaders/TileArray.frag | 18 ++ assets/shaders/TileArray.vert | 21 ++ assets/textures/Tile_Test.png | Bin 1202 -> 460 bytes assets/textures/Tile_Test_4.png | Bin 0 -> 246 bytes .../engine/graphics/front/geometry/Vertex.hpp | 10 - .../graphics/front/module/Quad_Module.hpp | 3 +- .../graphics/front/module/Sprite_Module.cpp | 2 +- .../front/module/TileArray_Module.cpp | 63 ++++++ .../front/module/TileArray_Module.hpp | 23 ++ .../graphics/front/object/TileArray.cpp | 27 +++ .../graphics/front/object/TileArray.hpp | 42 ++++ .../graphics/front/object/VerticesArray.cpp | 20 -- .../graphics/front/object/VerticesArray.hpp | 36 ---- source/main.cpp | 6 +- source/main.cpp.old | 198 ------------------ 16 files changed, 205 insertions(+), 268 deletions(-) create mode 100644 assets/shaders/TileArray.frag create mode 100644 assets/shaders/TileArray.vert create mode 100644 assets/textures/Tile_Test_4.png delete mode 100644 source/engine/graphics/front/geometry/Vertex.hpp create mode 100644 source/engine/graphics/front/module/TileArray_Module.cpp create mode 100644 source/engine/graphics/front/module/TileArray_Module.hpp create mode 100644 source/engine/graphics/front/object/TileArray.cpp create mode 100644 source/engine/graphics/front/object/TileArray.hpp delete mode 100644 source/engine/graphics/front/object/VerticesArray.cpp delete mode 100644 source/engine/graphics/front/object/VerticesArray.hpp delete mode 100644 source/main.cpp.old diff --git a/.gitignore b/.gitignore index e2a14a6..a3b8f73 100644 --- a/.gitignore +++ b/.gitignore @@ -11,9 +11,11 @@ *.exe *.git +*.ttf build/* include/* library/* vcpkg_installed/* -old/* \ No newline at end of file +old/* +old2/* \ No newline at end of file diff --git a/assets/shaders/TileArray.frag b/assets/shaders/TileArray.frag new file mode 100644 index 0000000..7b71e44 --- /dev/null +++ b/assets/shaders/TileArray.frag @@ -0,0 +1,18 @@ +#version 450 core +out vec4 FragColor; + +uniform sampler2D uSlot; + +uniform vec4 uUvs[128]; +uniform vec2 uSize; + +in vec2 Texture; +flat in int Id; + +void main() { + vec2 coord = vec2( + (uUvs[Id].x / uSize.x) + (uUvs[Id].z / uSize.x) * Texture.x, + (uUvs[Id].y / uSize.y) + (uUvs[Id].w / uSize.y) * Texture.y + ); + FragColor = texture(uSlot, coord); +} \ No newline at end of file diff --git a/assets/shaders/TileArray.vert b/assets/shaders/TileArray.vert new file mode 100644 index 0000000..a0e01e2 --- /dev/null +++ b/assets/shaders/TileArray.vert @@ -0,0 +1,21 @@ +#version 450 core +layout (location = 0) in vec2 aPos; +layout (location = 1) in vec2 aTex; + +uniform mat4 uModel; +uniform mat4 uView; +uniform mat4 uProj; + +uniform mat4 uOffsets[128]; + +out vec2 Texture; +flat out int Id; + +void main() { + Texture = aTex; + Id = gl_InstanceID; + vec2 pos = vec2(aPos.x, aPos.y); + + + gl_Position = uProj * uView * uModel * uOffsets[gl_InstanceID] * vec4(pos, 0.0, 1.0); +} \ No newline at end of file diff --git a/assets/textures/Tile_Test.png b/assets/textures/Tile_Test.png index d25e9e0324403cbccc67e1a0eed3fdbb9b63e694..c113642b3f04ce076c806252f8a3f93109b54b5a 100644 GIT binary patch delta 397 zcmdnQd4_p{XZ>LY2EN0L$MaXDFfcGCdb&7<M7TelmR)pMfv2UHfATkjx4FeL{PZ4Y z<xZJ+mWxIBlluLZ!Y0Ap9pRUha(*wD=e+lL`fW3j{Wd{fx*wen=1<9ca@Kh<&ziX# zo~1MHQn-7i(Lk8puQu@jS9owR^Wv?pifVUwcsk=*MZ>0R@+_!-IpK#w9^1X6)jTim zOkVk;fhWX`|Cv-qM{^|`)1!pG#swA?dmH%*17h4P_jK`E#JXwSJ9K1?kWi1-&E%(E zXYGF<EbV#z&AjZ_viFDooHrAz_wW8Aukh$nVdIv?f9js<^C^9D=@FYFrr0vm;=`-# zh(i8d+y+t6Qv`)|{n*wu)pM=RUbr|tbGwga$D&6HDGtH*lRCw&H0ZhMDrns^t`eBX zWGbYn#kYbnwr5+zw9XUTb_<<zIPH@EO0-I-YQxtB>WSxHtUX!4mR5MmA@}I*E1P+) ztnl^Ekgj^PK4I#)`J3C%*)o3P+i0|_acg~nzxOZp9Lt7Qzsl5n1_lNOPggcSmvv4F FO#lHcu;c&$ delta 1144 zcmX@ZyoqyyXZ-;N2EGG~S=Tx_85mgHJzX3_BHZ^*ug(c^6=|;z->AvTtDt*hm5q*4 zpzvas-|hV?1ch06w4&y_tcbcGk*wsVylvkiwPULkW(0Ty2ui#1DrL5qaB+PUY*tfq zofvdvm1tDtR*@BJ?!P&+Y4_gEuisw#mFoZO-p<X%^~S}|=IpF@>=jubTF25UuhVy2 zI5j>pesx2A+TYLeH<V{op5|V5$a%w!&)@IgUXp)r^0%DD-<2=D@Vw;ud1=$Zb&g$Y znBtDh9eLrkJZbHW{s|3dy_dG_-nn33LPyC9{b>7|o{+!$Ldv%7Eth$GYO&0bb;t9L z`WcFT*siU7abvXA{CfQ#K~?qt{8zqfFnQ~_a<bx{%IVotluVd?X7&7Y->7Y9{8v3O zO|7P4`hnxjhnLE=g<pTFrL$1dg8jFMvA+MM<&r1d1ew@Gcg+@2WVHLGtMILR%lcMR z+v}lAe$=z%L?xXzUVh7{w^4k<YvYw4IWrF}z4Y|^?o%QYSvE}myqNiXe4r+8TK(Vj zy-&1^C3i@^cr|6({f3U%OLN#(e$n}^Fu75%V8Y-3r+5~LUyk4EHmjtyTHx7!@q!t9 z^Wye>7S23&`OWL>JIwa?0`_niGhW$q;|WvqN!H_u$CK5()Hqoe{fcziynX4!r<ZPU z-}rxc$syr8&Kff{LeG?$%Q3P932xn7#Qkm7-g+Map@8y@Uk<00KYn<qGHB`TX%jq_ z?{$6h>DL$2*X36G)H&8PJo{keqG)lLv!nmCzrzI~mVMK=|5Mq!JMh=H>P;^br)~0? zRj!=5_lBv5@(hb}v6UGrA5BVczs}l|zUSj2A19`1kL^RxefE>ru03vMCL%WBRk-J5 z<I9zKjL!`x)vxEf`MP&;XUjuo&kX6hyFOa;wcp;=%FXxD>6hCT{A$_!R{dRWfh%t3 z$H$ee+57(E`bp)SRhPeM|BX4sGq0z4v&qYf^ati<1wZ>Q1sn@+YRKh?H22!I>V&C> zpr%0Sv7Ab!Xe%MpmWL9LZ$+KD6={FgO@;Bi-sY!oW^OxkQfy9rp62nJx7&+m$V{2v zFuicwZ7~mH%h|p&oE}7K+t%s3Z=D_69CO8}>M+;#)K7vJI{)W9XV~1lA>+)4kI#cX z`&G}K8ZP;hEiK`uM>ykuC51`C*Y>O4-8i8qN~!i>sph{aPgV%aEu8(y)@<1}mGhSi zf_HD3b>@=1`WmJEGgLDcuQ#oi-*xJq&Y|GwswILYmQT|&t)3sqzG)YI#!-G=a@6YY zpSDhxe4)%~&~tDhFMCYAqScEXGv1X6Seb9+dHqAKqTS<0m&RfDD|-)GF0?h?+0K$< zkY2>!t9Q`%n|#ia;}&IGC%b<aw%Z*!ZO3NIH*C(r6Ag}SzHD^3(8EFX`7tiL-okay zg4ZS5p7Y7r*Y`61FQf6Pz8z~0nf7>H;@tcr$>TuqcSD9{mAR8eji>KPNPC*NZ&jGx zW2vvLiaWzCSIj*B+*0|?*}Q#6lXN0Ka%6_wTIZ!+WcBWleV2_>*7uk4p~-fx5$no@ R85kHCJYD@<);T3K0RTQ2Ex!N& diff --git a/assets/textures/Tile_Test_4.png b/assets/textures/Tile_Test_4.png new file mode 100644 index 0000000000000000000000000000000000000000..b5db7d7c8c3da0f2ec9178caf6403d59193535d8 GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`&C3 z=<CS9u(6-}Pa-P=0|RG)M`SSr1K(i~W;~w1B87p0q1)5NF~q|E=%jAm1_d6Mi<%M# z17$8=lxfs8$+ao6<m#MwWV%E~b<EElZ;sb3<zI6?LNooN|I4S+&3jViBYP~fdZZ87 zzFM&28t;vpT!HGR3z;)s36=;RUwrFNc*SWO=6yE>R~0j>eA%S5;NYxh94`*UE|OWn x_UsJPJ>K)ahc`+W9J+AhMdrVM{6V`I#r}j}t_%A2j)8%J!PC{xWt~$(699i5UE%-$ literal 0 HcmV?d00001 diff --git a/source/engine/graphics/front/geometry/Vertex.hpp b/source/engine/graphics/front/geometry/Vertex.hpp deleted file mode 100644 index 4c3eed9..0000000 --- a/source/engine/graphics/front/geometry/Vertex.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include <glm/glm.hpp> - -namespace megu { - struct Vertex { - glm::vec2 _position; - glm::vec2 _texture; - }; -} \ No newline at end of file diff --git a/source/engine/graphics/front/module/Quad_Module.hpp b/source/engine/graphics/front/module/Quad_Module.hpp index cb8f305..5822de0 100644 --- a/source/engine/graphics/front/module/Quad_Module.hpp +++ b/source/engine/graphics/front/module/Quad_Module.hpp @@ -3,9 +3,10 @@ #include "Image_Module.hpp" #include "Sprite_Module.hpp" #include "Text_Module.hpp" +#include "TileArray_Module.hpp" namespace megu { - class Quad_Module : public Image_Module, public Sprite_Module, public Text_Module { + class Quad_Module : public Image_Module, public Sprite_Module, public Text_Module, public TileArray_Module { // ... }; } \ No newline at end of file diff --git a/source/engine/graphics/front/module/Sprite_Module.cpp b/source/engine/graphics/front/module/Sprite_Module.cpp index 2975d5c..691983f 100644 --- a/source/engine/graphics/front/module/Sprite_Module.cpp +++ b/source/engine/graphics/front/module/Sprite_Module.cpp @@ -74,7 +74,7 @@ namespace megu { this->_program.setUniform("uFrames", uFrames); this->_program.setUniform("uSizes", uSizes); - glDrawArraysInstanced(Quads::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(uModels.size())); + glDrawArraysInstanced(Sprite::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(uModels.size())); } } } \ No newline at end of file diff --git a/source/engine/graphics/front/module/TileArray_Module.cpp b/source/engine/graphics/front/module/TileArray_Module.cpp new file mode 100644 index 0000000..b88a30d --- /dev/null +++ b/source/engine/graphics/front/module/TileArray_Module.cpp @@ -0,0 +1,63 @@ +#include "TileArray_Module.hpp" + +#include <engine/graphics/back/cameras/Camera.hpp> +#include <glm/gtc/matrix_transform.hpp> + +namespace megu { + TileArray_Module::TileArray_Module() + : _vbo(this->_vao, TileArray::Layout(), TileArray::Vertices(), EditMode::STATIC) { + Source vert_source("assets/shaders/TileArray.vert", Source::Categorie::VERTEX); + this->_program << vert_source; + + Source frag_source("assets/shaders/TileArray.frag", Source::Categorie::FRAGMENT); + this->_program << frag_source; + + this->_program.link(); + vert_source.release(); + frag_source.release(); + } + + void TileArray_Module::draw(const TileArray & vertexArray, const Camera & camera, const Window &) const { + this->_vao.bind(); + this->_program.use(); + + this->_program.setUniform("uProj", camera.projection()); + this->_program.setUniform("uView", camera.view()); + this->_program.setUniform("uModel", vertexArray.transformation().model()); + + vertexArray.texture().bind(); + this->_program.setUniform("uSlot", 0); + this->_program.setUniform("uSize", glm::vec2{vertexArray.texture().width(), vertexArray.texture().height()}); + + std::vector<glm::mat4> uOffsets = {}; + std::vector<glm::vec4> uUvs = {}; + + size_t count = 0; + + for(size_t y = 0; y < vertexArray.height(); ++y) { + for(size_t x = 0; x < vertexArray.width(); ++x) { + uOffsets.push_back(glm::translate(glm::mat4(1.f), {x, y, 0.f})); + uUvs.push_back(vertexArray.uvs()[y][x]); + + if(count > 128) { + this->_program.setUniform("uOffsets", uOffsets); + this->_program.setUniform("uUvs", uUvs); + glDrawArraysInstanced(TileArray::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(vertexArray.width() * vertexArray.height())); + + uOffsets.clear(); + uUvs.clear(); + count = 0; + } + ++count; + } + } + + if(count != 0) { + this->_program.setUniform("uOffsets", uOffsets); + this->_program.setUniform("uUvs", uUvs); + //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glDrawArraysInstanced(TileArray::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(vertexArray.width() * vertexArray.height())); + //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } + } +} \ No newline at end of file diff --git a/source/engine/graphics/front/module/TileArray_Module.hpp b/source/engine/graphics/front/module/TileArray_Module.hpp new file mode 100644 index 0000000..d85204b --- /dev/null +++ b/source/engine/graphics/front/module/TileArray_Module.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "Module.hpp" + +#include <engine/graphics/back/buffers/VertexArray.hpp> +#include <engine/graphics/back/buffers/VerticeBuffer.hpp> +#include <engine/graphics/back/shaders/Program.hpp> + +#include <engine/graphics/front/object/TileArray.hpp> + +namespace megu { + class TileArray_Module : public Module<TileArray> { + public: + TileArray_Module(); + + virtual void draw(const TileArray &, const Camera &, const Window &) const override; + + private: + VertexArray _vao; + VerticeBuffer _vbo; + Program _program; + }; +} \ No newline at end of file diff --git a/source/engine/graphics/front/object/TileArray.cpp b/source/engine/graphics/front/object/TileArray.cpp new file mode 100644 index 0000000..bf10b68 --- /dev/null +++ b/source/engine/graphics/front/object/TileArray.cpp @@ -0,0 +1,27 @@ +#include "TileArray.hpp" + +#include <iostream> + +namespace megu { + TileArray::TileArray(const std::filesystem::path & path, size_t width, size_t height, float size) + : _width(width), _height(height), _size(size) { + megu::TextureBuffer buffer(path); + this->_texture.store(buffer); + + float twidth = static_cast<float>(this->_texture.width()); + float theight = static_cast<float>(this->_texture.height()); + + std::cout << twidth << "/" << theight << std::endl; + + for(size_t y = 0; y < height; ++y) { + std::vector<glm::vec4> rows; + for(size_t x = 0; x < width; ++x) { + rows.push_back({0.f, 0.f, twidth, theight}); + } + this->_uvs.push_back(rows); + } + + std::cout << this->_uvs.size() << std::endl; + this->_transformation.scale({size, size, 1.f}); + } +} \ No newline at end of file diff --git a/source/engine/graphics/front/object/TileArray.hpp b/source/engine/graphics/front/object/TileArray.hpp new file mode 100644 index 0000000..f3a8dcb --- /dev/null +++ b/source/engine/graphics/front/object/TileArray.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include <array> + +#include <engine/graphics/back/geometry/Transformable.hpp> +#include <engine/graphics/back/textures/Texture.hpp> +#include <engine/graphics/front/geometry/Quads.hpp> + +#include <engine/graphics/utility/type.hpp> + +namespace megu { + class TileArray : public Quads { + public: + TileArray(const std::filesystem::path &, size_t, size_t, float); + + inline void setPosition(const Vec2 & pos) {this->_transformation.setPosition(pos.x, pos.y);} + inline void setOrigine(const Vec2 & pos) {this->_transformation.setOrigine(pos.x, pos.y);} + inline void setSize(const Vec2 & size) {this->_transformation.setScaling(size.x, size.y);} + inline void setRotation(float a) {this->_transformation.setRotation(a, Transformable::Axis::Z);} + inline void setLayer(float l) {this->_transformation.setZ(l);} + + inline void move(const Vec2 & pos) {this->_transformation.move({pos.x, pos.y, 0.f});} + inline void scale(const Vec2 & size) {this->_transformation.scale({size.x, size.y, 0.f});} + inline void rotate(float a) {this->_transformation.rotate(a, Transformable::Axis::Z);} + + inline size_t width() const {return this->_width;} + inline size_t height() const {return this->_height;} + inline float size() const {return this->_size;} + + inline const Transformable & transformation() const {return this->_transformation;} + inline const Texture & texture() const {return this->_texture;} + + inline const std::vector<std::vector<glm::vec4>> & uvs() const {return this->_uvs;} + + private: + Transformable _transformation; + Texture _texture; + size_t _width, _height; + float _size; + std::vector<std::vector<glm::vec4>> _uvs; + }; +} \ No newline at end of file diff --git a/source/engine/graphics/front/object/VerticesArray.cpp b/source/engine/graphics/front/object/VerticesArray.cpp deleted file mode 100644 index 3a576ed..0000000 --- a/source/engine/graphics/front/object/VerticesArray.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "VerticesArray.hpp" - -namespace megu { - VerticesArray::VerticesArray(Primitive_t primitive, size_t size) - : _primitive(primitive), _vertices(size) {} - - VerticesArray::VerticesArray(const VerticesArray & src) - : _transformation(src._transformation), _primitive(src._primitive), _vertices(src._vertices) {} - - VerticesArray VerticesArray::operator=(const VerticesArray & src) { - this->_transformation = src._transformation; - this->_primitive = src._primitive; - this->_vertices = src._vertices; - return *this; - } - - void VerticesArray::append(const Vertex & vertex) { - this->_vertices.push_back(vertex); - } -} \ No newline at end of file diff --git a/source/engine/graphics/front/object/VerticesArray.hpp b/source/engine/graphics/front/object/VerticesArray.hpp deleted file mode 100644 index 550958f..0000000 --- a/source/engine/graphics/front/object/VerticesArray.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include <array> - -#include <engine/graphics/back/geometry/Transformable.hpp> -#include <engine/graphics/back/textures/Texture.hpp> -#include <engine/graphics/front/geometry/Quads.hpp> -#include <engine/graphics/front/geometry/Vertex.hpp> - -namespace megu { - class VerticesArray { - public: - VerticesArray(Primitive_t, size_t); - VerticesArray(const VerticesArray &); - VerticesArray operator=(const VerticesArray &); - ~VerticesArray() = default; - - inline size_t size() const {return this->_vertices.size();} - - void scale(float x, float y) {this->_transformation.scale(x, y);} - - void append(const Vertex &); - - const Transformable & transformation() const {return this->_transformation;} - const Primitive_t & primitive() const {return this->_primitive;} - const std::vector<Vertex> & vertices() const {return this->_vertices;} - - Vertex & operator[](size_t index) {return this->_vertices[index];} - const Vertex & operator[](size_t index) const {return this->_vertices[index];} - - private: - Transformable _transformation; - Primitive_t _primitive; - std::vector<Vertex> _vertices; - }; -} \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index a007791..ac230b0 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -16,6 +16,7 @@ #include <engine/graphics/front/object/Image.hpp> #include <engine/graphics/front/object/Sprite.hpp> #include <engine/graphics/front/object/Text.hpp> +#include <engine/graphics/front/object/TileArray.hpp> #include <engine/graphics/front/module/Quad_Module.hpp> #include <engine/graphics/front/engine/Renderer.hpp> #include <engine/graphics/front/engine/Engine.hpp> @@ -79,6 +80,8 @@ int main(int argc, const char * argv[]) { text.scale({200, 200}); + megu::TileArray tiles("assets/textures/Tile_Test_4.png", 3, 3, 32.f); + megu::GraphicEngine engine(window); megu::Renderer basic_renderer(128, 128); @@ -92,8 +95,9 @@ int main(int argc, const char * argv[]) { engine.push(0, basic_renderer); engine.push(0, 1, images_set, &modul); - engine.push(0, 0, sprites_set, &modul); + engine.push(0, 3, sprites_set, &modul); engine.push(0, 2, text, &modul); + engine.push(0, 0, tiles, &modul); double previousTime = megu::Window::Time(); int frameCount = 0; diff --git a/source/main.cpp.old b/source/main.cpp.old deleted file mode 100644 index d0207f2..0000000 --- a/source/main.cpp.old +++ /dev/null @@ -1,198 +0,0 @@ -#include <iostream> - -#include <GL/glew.h> -#include <GLFW/glfw3.h> - -#include <engine/graphics/errors.hpp> -#include <engine/graphics/back.hpp> - -#define NORMALIZE(X) X/255.f - -#define WINDOW_WIDTH 1200 -#define WINDOW_HEIGHT 720 - -int main(int argc, const char * argv[]) { - try { - //? GLFW - if(glfwInit() == GLFW_FALSE) { - std::cerr << "GLFW : GLFW Init Error" << std::endl; - return EXIT_FAILURE; - } - - GLFWmonitor * monitore = glfwGetPrimaryMonitor(); - const GLFWvidmode * videoMode = glfwGetVideoMode(monitore); - - glfwWindowHint(GLFW_RED_BITS, videoMode->redBits); - glfwWindowHint(GLFW_GREEN_BITS, videoMode->greenBits); - glfwWindowHint(GLFW_BLUE_BITS, videoMode->blueBits); - glfwWindowHint(GLFW_REFRESH_RATE, videoMode->refreshRate); - - glfwWindowHint(GLFW_RESIZABLE, true); - glfwWindowHint(GLFW_DECORATED, true); - glfwWindowHint(GLFW_VISIBLE, true); - glfwWindowHint(GLFW_DOUBLEBUFFER, true); - - GLFWwindow * window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Scene", NULL, NULL); - if(window == NULL) { - std::cerr << "GLFW : Window Init Error" << std::endl; - return EXIT_FAILURE; - } - - glfwMakeContextCurrent(window); - glfwSwapInterval(0); - std::cout << "GLFW Inited" << std::endl; - - //? Glew - if (glewInit()) { - std::cerr << "Failed to initialize GLAD" << std::endl; - return EXIT_FAILURE; - } - - std::cout << "Glew Inited" << std::endl; - - //? Viewport - glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); - - megu::error::opengl_error::check(); - std::cout << "Viewport" << std::endl; - - //? Buffers - megu::VertexArray vao; - megu::VerticeBuffer vbo(vao, {megu::layout::POSITION, megu::layout::COLOR}, 128, megu::EditMode::STATIC); - - std::vector<float> vertices = { - -1.f, -1.f, 0.f, NORMALIZE(33), NORMALIZE(114), NORMALIZE(255), - 1.f, -1.f, 0.f, NORMALIZE(33), NORMALIZE(114), NORMALIZE(255), - 1.f, 0.0f, 0.f, NORMALIZE(217), NORMALIZE(63), NORMALIZE(114), - - 1.f, 0.0f, 0.f, NORMALIZE(217), NORMALIZE(63), NORMALIZE(114), - -1.f, 0.0f, 0.f, NORMALIZE(217), NORMALIZE(63), NORMALIZE(114), - -1.f, -1.f, 0.f, NORMALIZE(33), NORMALIZE(114), NORMALIZE(255), - - -1.f, -0.0f, 0.f, NORMALIZE(217), NORMALIZE(63), NORMALIZE(114), - 1.f, -0.0f, 0.f, NORMALIZE(217), NORMALIZE(63), NORMALIZE(114), - 1.f, 1.f, 0.f, NORMALIZE(190), NORMALIZE(105), NORMALIZE(170), - - 1.f, 1.f, 0.f, NORMALIZE(190), NORMALIZE(105), NORMALIZE(170), - -1.f, 1.f, 0.f, NORMALIZE(190), NORMALIZE(105), NORMALIZE(170), - -1.f, 0.0f, 0.f, NORMALIZE(217), NORMALIZE(63), NORMALIZE(114) - }; - - vbo << vertices; - - std::cout << "VBO" << std::endl; - - megu::VertexArray vao_2; - megu::VerticeBuffer vbo_2(vao_2, {megu::layout::POSITION, megu::layout::COLOR}, 128, megu::EditMode::STATIC); - - std::vector<float> vertices_2 = { - -0.5f, -0.5f, 0.0, NORMALIZE(255), NORMALIZE(0), NORMALIZE(0), - 0.5f, -0.5f, 0.0, NORMALIZE(0), NORMALIZE(255), NORMALIZE(0), - 0.0f, 0.5f, 0.0, NORMALIZE(0), NORMALIZE(0), NORMALIZE(255), - }; - - vbo_2 << vertices_2; - - megu::VertexArray vao_F; - megu::VerticeBuffer vbo_F(vao_F, {megu::layout::POSITION, megu::layout::TEXTURE}, 64, megu::EditMode::STATIC); - - std::vector<float> vertices_F = { - -1.f, -1.f, 0.f, 0.f, 0.f, - 1.f, -1.f, 0.f, 1.f, 0.f, - 1.f, 1.f, 0.f, 1.f, 1.f, - - -1.f, -1.f, 0.f, 0.f, 0.f, - 1.f, 1.f, 0.f, 1.f, 1.f, - -1.f, 1.f, 0.f, 0.f, 1.f - }; - - vbo_F << vertices_F; - - std::cout << "VBO - FBO" << std::endl; - - //? Material - - megu::TextureBuffer buffer; - buffer.load("assets/textures/All_Might_Armored.png"); - - megu::Texture texture; - texture.store(buffer); - buffer.free(); - - //? FBO - - megu::FrameBuffer fbo(WINDOW_WIDTH, WINDOW_HEIGHT); - megu::FrameBuffer fbo_2(WINDOW_WIDTH, WINDOW_HEIGHT); - - //? Shaders - megu::Program program; - - { - megu::Source vertex("assets/shaders/Basic.vert", megu::Source::Categorie::VERTEX); - megu::Source fragment("assets/shaders/Basic.frag", megu::Source::Categorie::FRAGMENT); - - program << vertex; - program << fragment; - - program.link(); - } - - std::cout << "Shader - FBO" << std::endl; - - - megu::Program program_F; - - { - megu::Source vertex("assets/shaders/Texture.vert", megu::Source::Categorie::VERTEX); - megu::Source fragment("assets/shaders/Texture.frag", megu::Source::Categorie::FRAGMENT); - - program_F << vertex; - program_F << fragment; - - program_F.link(); - } - - std::cout << "Shader" << std::endl; - - - //? Render Loop - glClearColor(0.0f, 0.0f, 0.0f, 0.f); - - std::cout << "Render Loop Begin !" << std::endl; - while(!glfwWindowShouldClose(window)) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glfwPollEvents(); - - /*fbo.bind(); - vao.bind(); - program.use(); - glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(vbo.size())); - - fbo_2.bind(); - vao_2.bind(); - program.use(); - glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(vbo_2.size()));*/ - - megu::FrameBuffer::BindDefaultFrameBuffer(); - vao_F.bind(); - - //fbo.texture().bind(0); - //fbo_2.texture().bind(1); - - texture.bind(0); - - program_F.use(); - program_F.setUniform("uSamp", std::vector<GLint>({0, 1})); - - glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(vbo_F.size())); - - glfwSwapBuffers(window); - } - std::cout << "Render Loop End !" << std::endl; - } - catch(std::exception & error) { - std::cerr << error.what() << std::endl; - } - - return EXIT_SUCCESS; -} \ No newline at end of file -- GitLab