diff --git a/Makefile b/Makefile index b5bc88e..5fa637d 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ -# _______________ -# //`````````````\\ -# //~~~~~~~~~~~~~~~\\ + a game by @ohsqueezy (ohsqueezy.itch.io) & @sleepin (instagram.com/sleepin) -# //=================\\ + code is licensed for copy, modification and redistribution (git.nugget.fun/pudding) -# // \\ -# //-G--U--N--K--I--S--S-\\ 😀 Thank you for choosing Puddendo for your business 😀 -# //_______________________\\ -# ``````````````````````````` -# +# _______________ ,----------------------------------------------------------------. +# //`````````````\\ \ \ +# //~~~~~~~~~~~~~~~\\ \ by @ohsqueezy & @sleepin \ +# //=================\\ \ [ohsqueezy.itch.io] [sleepin.itch.io] \ +# // \\ \ \ +# // \\ \ code released under the zlib license [git.nugget.fun/pudding] \ +# // ☆ GUNKISS ☆ \\ \ \ +# //_________________________\\ `----------------------------------------------------------------' +# # This Makefile should build a Linux binary from `make linux`. Other platform targets have not been tested yet. ####################### @@ -71,6 +71,7 @@ $(SB_SRC_DIR)Pixels.o : $(addprefix $(SB_SRC_DIR),Box.hpp extension.hpp Log.hpp) $(SB_SRC_DIR)Audio.o : $(addprefix $(SB_SRC_DIR),Node.hpp Display.hpp Configuration.hpp Box.hpp filesystem.hpp extension.hpp) $(SB_SRC_DIR)Texture.o : $(addprefix $(SB_SRC_DIR),GLObject.hpp filesystem.hpp Log.hpp) $(SB_SRC_DIR)GLObject.o : $(addprefix $(SB_SRC_DIR),Log.hpp) +$(SB_SRC_DIR)Attributes.o : $(addprefix $(SB_SRC_DIR),Log.hpp extension.hpp) $(SRC_DIR)Item.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Texture.hpp Log.hpp) $(SRC_DIR)Pudding.o : $(SRC_H_FILES) $(SB_H_FILES) %.o : %.cpp %.hpp diff --git a/config.json b/config.json index 58d9eef..fe596c0 100644 --- a/config.json +++ b/config.json @@ -47,7 +47,7 @@ "enabled": true, "json-save": true, "json-save-directory": "local/scans", - "barcode": "613008719548", + "barcode": "", "capture-device": "/dev/video0" }, "api": diff --git a/lib/sb b/lib/sb index f70ea1c..1690bb5 160000 --- a/lib/sb +++ b/lib/sb @@ -1 +1 @@ -Subproject commit f70ea1c21595376ea8bc02d80140721eaf627520 +Subproject commit 1690bb5f1996c4f6e342cc59ffa05fa15f9d77ed diff --git a/src/Item.cpp b/src/Item.cpp index 6c1e2d0..f1f823b 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -1,3 +1,11 @@ +/* _______________ +---------------------------------------------------------------------------------------+ + //~~~~~~~~~~~~~\\ | a game by @ohsqueezy & @sleepin | + //```````````````\\ | [ohsqueezy.itch.io] [instagram.com/sleepin] | + //_0_0_0_0_0_0_0_0_\\ | | + //_/_/_/_/___\_\_\_\_\\ | with code licensed for copy, modification and redistribution [git.nugget.fun/pudding] | + //GGGUUUNNNKKKIIISSSSSS\\ | | +//_/__/__/__/_\__\__\__\_\\ | 😀 Thank you for choosing Puddendo for your business 😀 | + +---------------------------------------------------------------------------------------+ */ #include "Item.hpp" Item::Item(Node* parent) : Node(parent) {}; diff --git a/src/Item.hpp b/src/Item.hpp index f6811c5..2bd4856 100644 --- a/src/Item.hpp +++ b/src/Item.hpp @@ -1,3 +1,11 @@ +/* _______________ +---------------------------------------------------------------------------------------+ + //~~~~~~~~~~~~~\\ | a game by @ohsqueezy & @sleepin | + //```````````````\\ | [ohsqueezy.itch.io] [instagram.com/sleepin] | + //_0_0_0_0_0_0_0_0_\\ | | + //_/_/_/_/___\_\_\_\_\\ | with code licensed for copy, modification and redistribution [git.nugget.fun/pudding] | + //GGGUUUNNNKKKIIISSSSSS\\ | | +//_/__/__/__/_\__\__\__\_\\ | 😀 Thank you for choosing Puddendo for your business 😀 | + +---------------------------------------------------------------------------------------+ */ #ifndef Item_h_ #define Item_h_ diff --git a/src/Pudding.cpp b/src/Pudding.cpp index 809dd45..855bcb8 100644 --- a/src/Pudding.cpp +++ b/src/Pudding.cpp @@ -1,12 +1,11 @@ -/* - _______________ - //`````````````\\ + a game by @ohsqueezy (ohsqueezy.itch.io) & @sleepin (instagram.com/sleepin) - //~~~~~~~~~~~~~~~\\ + code is licensed for copy, modification and redistribution (git.nugget.fun/pudding) - //=================\\ - /// \\\ - ///G-*U-*N-*K-*I-*S-*S\\\ 😀 Thank you for choosing Puddendo for your business 😀 - //_______________________\\ - ``````````````````````````` +/* _______________ ,----------------------------------------------------------------. + //`````````````\\ \ \ + //~~~~~~~~~~~~~~~\\ \ by @ohsqueezy & @sleepin \ + //=================\\ \ [ohsqueezy.itch.io] [sleepin.itch.io] \ + // \\ \ \ + // \\ \ code released under the zlib license [git.nugget.fun/pudding] \ + // ☆ GUNKISS ☆ \\ \ \ + //_________________________\\ `----------------------------------------------------------------' Generate a custom pudding from food product UPC codes and help a pair of rats take over the video game industry, using their extraterrestrial ability to turn trash into performance enhancing drug puddings that enable business professionals @@ -93,30 +92,30 @@ void Pudding::set_pudding_model( /* triangle that includes top two vertices and first base vertex */ start_vertex = &layer_top_ring[ii]; end_vertex = &layer_top_ring[(ii + 1) % layer_top_ring.size()]; - pudding_vertices.push_back({start_vertex->x, layer_top_y, start_vertex->y}); - pudding_uv.push_back({ring_start_vertex_u, layer_top_percent}); - pudding_vertices.push_back({end_vertex->x, layer_top_y, end_vertex->y}); - pudding_uv.push_back({ring_start_vertex_u + u_step, layer_top_percent}); - pudding_colors.insert(pudding_colors.end(), 2, *layer_top_color); - pudding_vertices.push_back({layer_base_ring[ii].x, layer_base_y, layer_base_ring[ii].y}); - pudding_uv.push_back({ring_start_vertex_u, layer_base_percent}); - pudding_colors.push_back(*layer_bottom_color); + pudding_attributes["vertices"].add(start_vertex->x, layer_top_y, start_vertex->y); + pudding_attributes["uv"].add(ring_start_vertex_u, layer_top_percent); + pudding_attributes["vertices"].add(end_vertex->x, layer_top_y, end_vertex->y); + pudding_attributes["uv"].add(ring_start_vertex_u + u_step, layer_top_percent); + pudding_attributes["color"].extend(*layer_top_color, 2); + pudding_attributes["vertices"].add(layer_base_ring[ii].x, layer_base_y, layer_base_ring[ii].y); + pudding_attributes["uv"].add(ring_start_vertex_u, layer_base_percent); + pudding_attributes["color"].add(*layer_bottom_color); /* triangle that includes bottom two vertices and second top vertex */ start_vertex = &layer_base_ring[ii]; - pudding_vertices.push_back({start_vertex->x, layer_base_y, start_vertex->y}); - pudding_uv.push_back({ring_start_vertex_u, layer_base_percent}); - pudding_colors.push_back(*layer_bottom_color); - pudding_vertices.push_back({end_vertex->x, layer_top_y, end_vertex->y}); - pudding_uv.push_back({ring_start_vertex_u + u_step, layer_top_percent}); - pudding_colors.push_back(*layer_top_color); + pudding_attributes["vertices"].add(start_vertex->x, layer_base_y, start_vertex->y); + pudding_attributes["uv"].add(ring_start_vertex_u, layer_base_percent); + pudding_attributes["colors"].add(*layer_bottom_color); + pudding_attributes["vertices"].add(end_vertex->x, layer_top_y, end_vertex->y); + pudding_attributes["uv"].add(ring_start_vertex_u + u_step, layer_top_percent); + pudding_attributes["color"].add(*layer_top_color); end_vertex = &layer_base_ring[(ii + 1) % layer_base_ring.size()]; - pudding_vertices.push_back({end_vertex->x, layer_base_y, end_vertex->y}); - pudding_uv.push_back({ring_start_vertex_u + u_step, layer_base_percent}); - pudding_colors.push_back(*layer_bottom_color); + pudding_attributes["vertices"].add(end_vertex->x, layer_base_y, end_vertex->y); + pudding_attributes["uv"].add(ring_start_vertex_u + u_step, layer_base_percent); + pudding_attributes["color"].add(*layer_bottom_color); ring_start_vertex_u += u_step; } } - pudding_triangle_vertex_count = pudding_vertices.size(); + pudding_triangle_vertex_count = pudding_attributes["vertices"].count(); /* process the top and bottom of pudding, filling each face with a triangle fan */ float y = max_y; const glm::vec3* face_color = &PUDDING_BROWN; @@ -124,8 +123,8 @@ void Pudding::set_pudding_model( for (float radius : {top_radius, base_radius}) { /* first point in a GL_TRIANGLE_FAN is the center */ - pudding_vertices.push_back({0, y, 0}); - pudding_uv.push_back({0, 0}); + pudding_attributes["vertices"].add(0.0f, y, 0.0f); + pudding_attributes["uv"].add(0.0f, 0.0f); layer_top_ring.clear(); sb::points_on_circle(layer_top_ring, ring_vertex_count, radius); /* loop through points on the face */ @@ -133,22 +132,22 @@ void Pudding::set_pudding_model( { start_vertex = &layer_top_ring[ii]; /* for GL_TRIANGLE_FAN we just need to add an outer vertex */ - pudding_vertices.push_back({start_vertex->x, y, start_vertex->y}); - pudding_uv.push_back(*start_vertex); + pudding_attributes["vertices"].add(start_vertex->x, y, start_vertex->y); + pudding_attributes["uv"].add(*start_vertex); /* connect the ring on the last vertex */ if (ii == layer_top_ring.size() - 1) { end_vertex = &layer_top_ring[(ii + 1) % layer_top_ring.size()]; - pudding_vertices.push_back({end_vertex->x, y, end_vertex->y}); - pudding_uv.push_back(*end_vertex); + pudding_attributes["vertices"].add(end_vertex->x, y, end_vertex->y); + pudding_attributes["uv"].add(*end_vertex); } } /* single color for the entire layer_top_ring */ - pudding_colors.insert(pudding_colors.end(), layer_top_ring.size() + 2, *face_color); + pudding_attributes["colors"].extend(*face_color, layer_top_ring.size() + 2); y = min_y; face_color = &PUDDING_YELLOW; } - pudding_fan_vertex_count = (pudding_vertices.size() - pudding_triangle_vertex_count) / 2; + pudding_fan_vertex_count = (pudding_attributes["vertices"].count() - pudding_triangle_vertex_count) / 2; } /* Create GL context via super class and load vertices, UV data, and shaders */ @@ -164,16 +163,19 @@ void Pudding::load_gl_context() /* Generate a vertex array object ID, bind it as current */ vao.generate(); vao.bind(); - /* 2D vertices for any texture that is a plane spanning the screen */ - std::array rectangle_vertices = {{ - {-1.0f, 1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f}, - {1.0f, 1.0f}, {1.0f, -1.0f}, {-1.0f, -1.0f} - }}; - /* UV map for mapping a texture onto a plane */ - std::array rectangle_uv = {{ - {0.0f, 1.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}, - {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 0.0f} - }}; + /* 2D attributes (location and UV) for any texture that is a plane spanning the screen */ + std::vector rectangle_attributes = { + /* rectangle vertices will be added later */ + sb::Attributes({ + {-1.0f, 1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f}, + {1.0f, 1.0f}, {1.0f, -1.0f}, {-1.0f, -1.0f} + }), + /* first three rectangle UV coordinates, three more will be added later */ + sb::Attributes({ + {0.0f, 1.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}, + {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 0.0f} + }) + }; /* Generate one vertex buffer object to hold all vertices and rectangle UV map. Since we're using one buffer, data * will be copied in one after the other, offset to after the previous data location. The same buffer offset will * be passed to the vertex attributes for each data. */ @@ -181,26 +183,26 @@ void Pudding::load_gl_context() vbo.target(GL_ARRAY_BUFFER); vbo.bind(); /* allocate space for vertices, UV and colors, and copy rectangle vertices in at initialization */ - GLsizeiptr vbo_size = (rectangle_vertices.size() + rectangle_uv.size() + pudding_uv.size()) * sizeof(glm::vec2) + - (pudding_vertices.size() + pudding_colors.size()) * sizeof(glm::vec3); - glBufferData(GL_ARRAY_BUFFER, vbo_size, rectangle_vertices.data(), GL_STATIC_DRAW); + GLsizeiptr vbo_size = rectangle_attributes[0].size() + rectangle_attributes[1].size() + pudding_attributes["uv"].size() + + pudding_attributes["vertices"].size() + pudding_attributes["colors"].size(); + glBufferData(GL_ARRAY_BUFFER, vbo_size, rectangle_attributes[0], GL_STATIC_DRAW); /* specify the rectangle vertex attributes as consecutive 2D float coords */ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr); /* copy rectangle UV data into the VBO, offset to after the vertex data, set up attributes */ - GLintptr offset = rectangle_vertices.size() * sizeof(glm::vec2); - glBufferSubData(GL_ARRAY_BUFFER, offset, rectangle_uv.size() * sizeof(glm::vec2), rectangle_uv.data()); + GLintptr offset = rectangle_attributes[0].size(); + glBufferSubData(GL_ARRAY_BUFFER, offset, rectangle_attributes[1].size(), rectangle_attributes[1]); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, reinterpret_cast(offset)); /* copy pudding vertices into VBO, offset to after the rectangle UV, and set up vertex attributes for 3D */ - offset += rectangle_uv.size() * sizeof(glm::vec2); - glBufferSubData(GL_ARRAY_BUFFER, offset, pudding_vertices.size() * sizeof(glm::vec3), pudding_vertices.data()); + offset += rectangle_attributes[1].size(); + glBufferSubData(GL_ARRAY_BUFFER, offset, pudding_attributes["vertices"].size(), pudding_attributes["vertices"]); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, reinterpret_cast(offset)); /* copy pudding color values into VBO, offset to after pudding vertices and set as 3D */ - offset += pudding_vertices.size() * sizeof(glm::vec3); - glBufferSubData(GL_ARRAY_BUFFER, offset, pudding_colors.size() * sizeof(glm::vec3), pudding_colors.data()); + offset += pudding_attributes["vertices"].size(); + glBufferSubData(GL_ARRAY_BUFFER, offset, pudding_attributes["colors"].size(), pudding_attributes["colors"]); glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, reinterpret_cast(offset)); /* copy pudding UV values into VBO, offset to after pudding color vertices and set as 2D */ - offset += pudding_colors.size() * sizeof(glm::vec3); - glBufferSubData(GL_ARRAY_BUFFER, offset, pudding_uv.size() * sizeof(glm::vec2), pudding_uv.data()); + offset += pudding_attributes["colors"].size(); + glBufferSubData(GL_ARRAY_BUFFER, offset, pudding_attributes["uv"].size(), pudding_attributes["uv"]); glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, 0, reinterpret_cast(offset)); /* Load two shader programs, one for rendering the flat objects, and one for rendering the 3D model. Load, configure, * and link the flat shader program first. */ diff --git a/src/Pudding.hpp b/src/Pudding.hpp index 044e75c..2f5e9e8 100644 --- a/src/Pudding.hpp +++ b/src/Pudding.hpp @@ -1,3 +1,12 @@ +/* _______________ ,----------------------------------------------------------------. + //`````````````\\ \ \ + //~~~~~~~~~~~~~~~\\ \ by @ohsqueezy & @sleepin \ + //=================\\ \ [ohsqueezy.itch.io] [sleepin.itch.io] \ + // \\ \ \ + // \\ \ code released under the zlib license [git.nugget.fun/pudding] \ + // ☆ GUNKISS ☆ \\ \ \ +//_________________________\\ `---------------------------------------------------------------*/ + #ifndef Pudding_h_ #define Pudding_h_ @@ -7,10 +16,7 @@ #include #include #include -#include -#include #include -#include #include "SDL.h" #include "SDL_image.h" #include "sdl2-gfx/SDL2_gfxPrimitives.h" @@ -24,11 +30,13 @@ #include "Game.hpp" #include "Color.hpp" #include "extension.hpp" +#include "filesystem.hpp" #include "Item.hpp" #include "Animation.hpp" #include "Texture.hpp" #include "GLObject.hpp" #include "Log.hpp" +#include "Attributes.hpp" class VAO : public GLObject { @@ -49,29 +57,6 @@ public: void vao_deleter(GLuint*); -class Attributes -{ - -private: - - using Vertices1D = std::vector>; - using Vertices2D = std::vector, glm::defaultp>>; - using Vertices3D = std::vector, glm::defaultp>>; - using Vertices4D = std::vector, glm::defaultp>>; - using Vertices = std::vector>; - std::vector vertices; - -public: - - Attributes(); - Attributes(Vertices); - Attributes(std::vector); - void index(int); - int index() const; - void enable() const; - -}; - class Buffer : public GLObject { @@ -84,6 +69,7 @@ public: Buffer(); Buffer(GLenum, GLenum); + void generate(); void target(GLenum); GLenum target() const; @@ -92,7 +78,7 @@ public: void allocate(GLenum, GLenum, GLsizeiptr); template - Attributes add(VAO& vao, std::vector vertex_attributes) + sb::Attributes add(VAO& vao, std::vector vertex_attributes) { vao.increment(); // glVertexAttribPointer(vao.counted(), @@ -147,6 +133,11 @@ private: uv_transformation_uniform_location, flat_texture_uniform_location, coordinate_bound_uniform_location, flat_time_uniform_location, scroll_uniform_location; glm::mat4 projection, model = glm::mat4(1.0f), mvp; + std::map pudding_attributes = { + {"vertices", sb::Attributes()}, + {"uv", sb::Attributes()}, + {"color", sb::Attributes()} + }; std::vector pudding_vertices, pudding_colors; std::vector pudding_uv; bool show_item = false, reading_capture_frame = false; diff --git a/src/flat.frag b/src/flat.frag index ef87422..fda74f7 100644 --- a/src/flat.frag +++ b/src/flat.frag @@ -1,3 +1,11 @@ +/* _______________ +---------------------------------------------------------------------------------------+ + //~~~~~~~~~~~~~\\ | a game by @ohsqueezy & @sleepin | + //```````````````\\ | [ohsqueezy.itch.io] [instagram.com/sleepin] | + //_0_0_0_0_0_0_0_0_\\ | | + //_/_/_/_/___\_\_\_\_\\ | with code licensed for copy, modification and redistribution [git.nugget.fun/pudding] | + //GGGUUUNNNKKKIIISSSSSS\\ | | +//_/__/__/__/_\__\__\__\_\\ | 😀 Thank you for choosing Puddendo for your business 😀 | + +---------------------------------------------------------------------------------------+ */ #version 130 in vec2 uv; diff --git a/src/flat.vert b/src/flat.vert index f0bdc63..3322c84 100644 --- a/src/flat.vert +++ b/src/flat.vert @@ -1,3 +1,11 @@ +/* _______________ +---------------------------------------------------------------------------------------+ + //~~~~~~~~~~~~~\\ | a game by @ohsqueezy & @sleepin | + //```````````````\\ | [ohsqueezy.itch.io] [instagram.com/sleepin] | + //_0_0_0_0_0_0_0_0_\\ | | + //_/_/_/_/___\_\_\_\_\\ | with code licensed for copy, modification and redistribution [git.nugget.fun/pudding] | + //GGGUUUNNNKKKIIISSSSSS\\ | | +//_/__/__/__/_\__\__\__\_\\ | 😀 Thank you for choosing Puddendo for your business 😀 | + +---------------------------------------------------------------------------------------+ */ #version 130 in vec2 in_position; diff --git a/src/mvp.frag b/src/mvp.frag index 07e0de0..3f70823 100644 --- a/src/mvp.frag +++ b/src/mvp.frag @@ -1,3 +1,11 @@ +/* _______________ +---------------------------------------------------------------------------------------+ + //~~~~~~~~~~~~~\\ | a game by @ohsqueezy & @sleepin | + //```````````````\\ | [ohsqueezy.itch.io] [instagram.com/sleepin] | + //_0_0_0_0_0_0_0_0_\\ | | + //_/_/_/_/___\_\_\_\_\\ | with code licensed for copy, modification and redistribution [git.nugget.fun/pudding] | + //GGGUUUNNNKKKIIISSSSSS\\ | | +//_/__/__/__/_\__\__\__\_\\ | 😀 Thank you for choosing Puddendo for your business 😀 | + +---------------------------------------------------------------------------------------+ */ #version 130 #define TRANSFORMATION_NONE 0 diff --git a/src/mvp.vert b/src/mvp.vert index c0bd1d8..08cf63f 100644 --- a/src/mvp.vert +++ b/src/mvp.vert @@ -1,3 +1,11 @@ +/* _______________ +---------------------------------------------------------------------------------------+ + //~~~~~~~~~~~~~\\ | a game by @ohsqueezy & @sleepin | + //```````````````\\ | [ohsqueezy.itch.io] [instagram.com/sleepin] | + //_0_0_0_0_0_0_0_0_\\ | | + //_/_/_/_/___\_\_\_\_\\ | with code licensed for copy, modification and redistribution [git.nugget.fun/pudding] | + //GGGUUUNNNKKKIIISSSSSS\\ | | +//_/__/__/__/_\__\__\__\_\\ | 😀 Thank you for choosing Puddendo for your business 😀 | + +---------------------------------------------------------------------------------------+ */ #version 130 #define PI 3.1415926535897932384626433832795