diff options
Diffstat (limited to 'include/YAGE')
-rw-r--r-- | include/YAGE/camera2d.hpp | 36 | ||||
-rw-r--r-- | include/YAGE/glslprogram.hpp (renamed from include/YAGE/glsl_program.hpp) | 4 | ||||
-rw-r--r-- | include/YAGE/gltexture.hpp (renamed from include/YAGE/gl_texture.hpp) | 5 | ||||
-rw-r--r-- | include/YAGE/imageloader.hpp (renamed from include/YAGE/image_loader.hpp) | 8 | ||||
-rw-r--r-- | include/YAGE/iomanager.hpp (renamed from include/YAGE/io_manager.hpp) | 6 | ||||
-rw-r--r-- | include/YAGE/logger.hpp | 24 | ||||
-rw-r--r-- | include/YAGE/picopng.hpp (renamed from include/YAGE/pico_png.hpp) | 5 | ||||
-rw-r--r-- | include/YAGE/resourcemanager.hpp (renamed from include/YAGE/resource_manager.hpp) | 10 | ||||
-rw-r--r-- | include/YAGE/sprite.hpp | 7 | ||||
-rw-r--r-- | include/YAGE/spritebatch.hpp | 52 | ||||
-rw-r--r-- | include/YAGE/texturecache.hpp (renamed from include/YAGE/texture_cache.hpp) | 8 | ||||
-rw-r--r-- | include/YAGE/vertex.hpp | 5 | ||||
-rw-r--r-- | include/YAGE/window.hpp | 22 |
13 files changed, 154 insertions, 38 deletions
diff --git a/include/YAGE/camera2d.hpp b/include/YAGE/camera2d.hpp new file mode 100644 index 00000000..030b0a37 --- /dev/null +++ b/include/YAGE/camera2d.hpp @@ -0,0 +1,36 @@ +#ifndef CAMERA_2D_HPP +#define CAMERA_2D_HPP + +#include <glm/glm.hpp> +#include <glm/gtc/matrix_transform.hpp> + +namespace yage +{ + +class Camera2D +{ +private: + bool matrix_needs_update_=true; + float scale_=1.f; + glm::vec2 position_; + glm::mat4 camera_matrix_; + glm::mat4 ortho_matrix_; +public: + Camera2D(int screen_width=1280, int screen_height=720); + virtual ~Camera2D(); + + void update(); + + // setters + void setPosition(const glm::vec2 &new_position) { position_=new_position; matrix_needs_update_=true; } + void setScale(float new_scale) {scale_=new_scale; matrix_needs_update_=true; } + + // getters + float getScale() { return scale_; } + glm::vec2 getPosition() { return position_; } + glm::mat4 getCameraMatrix() { return camera_matrix_; } +}; + +} // yage + +#endif diff --git a/include/YAGE/glsl_program.hpp b/include/YAGE/glslprogram.hpp index cef38a8e..3e03723a 100644 --- a/include/YAGE/glsl_program.hpp +++ b/include/YAGE/glslprogram.hpp @@ -5,6 +5,9 @@ #include <string> +namespace yage +{ + class GlslProgram { private: @@ -29,5 +32,6 @@ public: void unuse(); }; +} // yage #endif diff --git a/include/YAGE/gl_texture.hpp b/include/YAGE/gltexture.hpp index 808d86b1..7446d560 100644 --- a/include/YAGE/gl_texture.hpp +++ b/include/YAGE/gltexture.hpp @@ -3,11 +3,16 @@ #include <GL/glew.h> +namespace yage +{ + struct GlTexture { GLuint id; int width; int height; }; + +} // yage #endif diff --git a/include/YAGE/image_loader.hpp b/include/YAGE/imageloader.hpp index 5f7b97f0..632897dc 100644 --- a/include/YAGE/image_loader.hpp +++ b/include/YAGE/imageloader.hpp @@ -1,15 +1,19 @@ #ifndef IMAGE_LOADER_HPP #define IMAGE_LOADER_HPP -#include "gl_texture.hpp" +#include "gltexture.hpp" #include <string> +namespace yage +{ + class ImageLoader { public: static GlTexture loadPng(const std::string &file_path); }; - + +} // yage #endif diff --git a/include/YAGE/io_manager.hpp b/include/YAGE/iomanager.hpp index 05d288b5..ef80b515 100644 --- a/include/YAGE/io_manager.hpp +++ b/include/YAGE/iomanager.hpp @@ -4,11 +4,15 @@ #include <string> #include <vector> +namespace yage +{ + class IoManager { public: static bool readFileToBuffer(const std::string &file_path, std::vector<unsigned char> &buffer); }; - + +} // yage #endif diff --git a/include/YAGE/logger.hpp b/include/YAGE/logger.hpp deleted file mode 100644 index 36c7b9b3..00000000 --- a/include/YAGE/logger.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef LOGGER_HPP -#define LOGGER_HPP - -#include <string> - -class Logger -{ -public: - template<typename Tail> - static std::string log(std::ostream &out, Tail &&tail) - { - out<<tail; - } - - template<typename Head, typename... Tail> - static std::string log(std::ostream &out, Head &&head, Tail &&...tail) - { - out<<std::forward<Head>(head); - log(out, std::forward<Tail>(tail)...); - } -}; - - -#endif diff --git a/include/YAGE/pico_png.hpp b/include/YAGE/picopng.hpp index ef123573..8fea4f0d 100644 --- a/include/YAGE/pico_png.hpp +++ b/include/YAGE/picopng.hpp @@ -1,4 +1,9 @@ #include <vector> #include <cstdlib> +namespace yage +{ + extern int decodePNG(std::vector<unsigned char> &out_image, unsigned long &image_width, unsigned long &image_height, const unsigned char *in_png, size_t in_size, bool convert_to_rgba32 = true); + +} // yage diff --git a/include/YAGE/resource_manager.hpp b/include/YAGE/resourcemanager.hpp index 155515a3..08ab31e0 100644 --- a/include/YAGE/resource_manager.hpp +++ b/include/YAGE/resourcemanager.hpp @@ -1,11 +1,14 @@ #ifndef RESOURCE_MANAGER_HPP #define RESOURCE_MANAGER_HPP -#include "gl_texture.hpp" -#include "texture_cache.hpp" +#include "gltexture.hpp" +#include "texturecache.hpp" #include <string> +namespace yage +{ + class ResourceManager { private: @@ -13,6 +16,7 @@ private: public: static GlTexture getTexture(const std::string &texture_path); }; - + +} // yage #endif diff --git a/include/YAGE/sprite.hpp b/include/YAGE/sprite.hpp index 9f765c7d..8abc339a 100644 --- a/include/YAGE/sprite.hpp +++ b/include/YAGE/sprite.hpp @@ -1,12 +1,15 @@ #ifndef SPRITE_HPP #define SPRITE_HPP -#include "gl_texture.hpp" +#include "gltexture.hpp" #include <GL/glew.h> #include <string> +namespace yage +{ + class Sprite { private: @@ -23,5 +26,7 @@ public: void init(float x, float y, float width, float height, const std::string &texture_path); void draw(); }; + +} // yage #endif diff --git a/include/YAGE/spritebatch.hpp b/include/YAGE/spritebatch.hpp new file mode 100644 index 00000000..fcc6faec --- /dev/null +++ b/include/YAGE/spritebatch.hpp @@ -0,0 +1,52 @@ +#ifndef SPRITE_BATCH_HPP +#define SPRITE_BATCH_HPP + +#include "vertex.hpp" + +#include <GL/glew.h> +#include <glm/glm.hpp> + +#include <vector> + +namespace yage +{ + +struct Glyph +{ + GLuint texture; + float depth; + + Vertex top_left; + Vertex top_right; + Vertex bottom_right; + Vertex bottom_left; +}; + +class SpriteBatch +{ +public: // member variables +private: + GLuint vbo_=0; + GLuint vao_=0; + + std::vector<Glyph> glyphs_; + std::vector<Glyph *> glyph_ptrs_; + +public: // member functions + SpriteBatch(); + ~SpriteBatch(); + + void begin(); + void end(); + + void draw(const glm::vec4 &destination_rect, const glm::vec4 &uv_rect, GLuint texture, const Color &color, float depth); + + void renderBatch(); +private: + void createVertexArray(); + void sortGlyphs(); +}; + +} // yage + +#endif diff --git a/include/YAGE/texture_cache.hpp b/include/YAGE/texturecache.hpp index 44dba2f8..43266ee9 100644 --- a/include/YAGE/texture_cache.hpp +++ b/include/YAGE/texturecache.hpp @@ -1,10 +1,13 @@ #ifndef TEXTURE_CACHE_HPP #define TEXTURE_CACHE_HPP -#include "gl_texture.hpp" +#include "gltexture.hpp" #include <unordered_map> +namespace yage +{ + class TextureCache { private: @@ -15,6 +18,7 @@ public: GlTexture getTexture(const std::string &texture_path); }; - + +} // yage #endif diff --git a/include/YAGE/vertex.hpp b/include/YAGE/vertex.hpp index d9ab1138..5826aeee 100644 --- a/include/YAGE/vertex.hpp +++ b/include/YAGE/vertex.hpp @@ -3,6 +3,9 @@ #include <GL/glew.h> +namespace yage +{ + struct Position { float x; @@ -49,5 +52,7 @@ struct Vertex uv.v = v; } }; + +} // yage #endif diff --git a/include/YAGE/window.hpp b/include/YAGE/window.hpp index 6f3058e9..5f104912 100644 --- a/include/YAGE/window.hpp +++ b/include/YAGE/window.hpp @@ -5,7 +5,11 @@ #include <string> -enum class WindowFlags +namespace yage +{ + +// window flags that can change it's appearance +enum WindowFlags : unsigned { SHOWN=0x1, HIDDEN=0x2, @@ -13,18 +17,26 @@ enum class WindowFlags BORDERLESS=0x8, }; +// window wrapper around SDL_Window pointer class Window { +public: // member variables private: + // window handle SDL_Window *window_=nullptr; - int width_=1280; - int height_=720; -public: +public: // member functions Window(); + // destroys the window handle ~Window(); - void create(const std::string &window_name, int width, int height, WindowFlags flags=WindowFlags::SHOWN); + // create the window, initialize the handle and update the width and height + void create(const std::string &window_name, int width, int height, unsigned flags=WindowFlags::SHOWN); + // swap the buffer + void swapBuffer(); +private: }; + +} // yage #endif |