From 21a147c3c1c2fad2819fe76becab320c51eb131f Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 2 Apr 2017 09:15:30 +0100 Subject: Adding initial files --- include/yage/gl_texture.hpp | 13 ++++++++++ include/yage/glsl_program.hpp | 33 ++++++++++++++++++++++++ include/yage/image_loader.hpp | 15 +++++++++++ include/yage/io_manager.hpp | 14 +++++++++++ include/yage/logger.hpp | 24 ++++++++++++++++++ include/yage/pico_png.hpp | 4 +++ include/yage/resource_manager.hpp | 18 +++++++++++++ include/yage/sprite.hpp | 27 ++++++++++++++++++++ include/yage/texture_cache.hpp | 20 +++++++++++++++ include/yage/vertex.hpp | 53 +++++++++++++++++++++++++++++++++++++++ include/yage/window.hpp | 30 ++++++++++++++++++++++ 11 files changed, 251 insertions(+) create mode 100644 include/yage/gl_texture.hpp create mode 100644 include/yage/glsl_program.hpp create mode 100644 include/yage/image_loader.hpp create mode 100644 include/yage/io_manager.hpp create mode 100644 include/yage/logger.hpp create mode 100644 include/yage/pico_png.hpp create mode 100644 include/yage/resource_manager.hpp create mode 100644 include/yage/sprite.hpp create mode 100644 include/yage/texture_cache.hpp create mode 100644 include/yage/vertex.hpp create mode 100644 include/yage/window.hpp (limited to 'include') diff --git a/include/yage/gl_texture.hpp b/include/yage/gl_texture.hpp new file mode 100644 index 00000000..808d86b1 --- /dev/null +++ b/include/yage/gl_texture.hpp @@ -0,0 +1,13 @@ +#ifndef GL_TEXTURE_HPP +#define GL_TEXTURE_HPP + +#include + +struct GlTexture +{ + GLuint id; + int width; + int height; +}; + +#endif diff --git a/include/yage/glsl_program.hpp b/include/yage/glsl_program.hpp new file mode 100644 index 00000000..cef38a8e --- /dev/null +++ b/include/yage/glsl_program.hpp @@ -0,0 +1,33 @@ +#ifndef GLSL_PROGRAM_HPP +#define GLSL_PROGRAM_HPP + +#include + +#include + +class GlslProgram +{ +private: + // compiled shader program id + GLuint program_id_ = 0; + GLuint vertex_shader_id_ = 0; + GLuint fragment_shader_id_ = 0; + int attribute_index_ = 0; + + // compiles one shader + void compileShader(const GLuint &shader, const std::string &file_path); +public: + GlslProgram(); + ~GlslProgram(); + + // compiles vertex and fragment shader + void compileShaders(const std::string &vertex_shader_path, const std::string &fragment_shader_path); + void linkShaders(); + void addAttribute(const std::string &attribute_name); + GLint getUniformLocation(const std::string &uniform_name); + void use(); + void unuse(); +}; + + +#endif diff --git a/include/yage/image_loader.hpp b/include/yage/image_loader.hpp new file mode 100644 index 00000000..5f7b97f0 --- /dev/null +++ b/include/yage/image_loader.hpp @@ -0,0 +1,15 @@ +#ifndef IMAGE_LOADER_HPP +#define IMAGE_LOADER_HPP + +#include "gl_texture.hpp" + +#include + +class ImageLoader +{ +public: + static GlTexture loadPng(const std::string &file_path); +}; + + +#endif diff --git a/include/yage/io_manager.hpp b/include/yage/io_manager.hpp new file mode 100644 index 00000000..05d288b5 --- /dev/null +++ b/include/yage/io_manager.hpp @@ -0,0 +1,14 @@ +#ifndef IO_MANAGER_HPP +#define IO_MANAGER_HPP + +#include +#include + +class IoManager +{ +public: + static bool readFileToBuffer(const std::string &file_path, std::vector &buffer); +}; + + +#endif diff --git a/include/yage/logger.hpp b/include/yage/logger.hpp new file mode 100644 index 00000000..36c7b9b3 --- /dev/null +++ b/include/yage/logger.hpp @@ -0,0 +1,24 @@ +#ifndef LOGGER_HPP +#define LOGGER_HPP + +#include + +class Logger +{ +public: + template + static std::string log(std::ostream &out, Tail &&tail) + { + out< + static std::string log(std::ostream &out, Head &&head, Tail &&...tail) + { + out<(head); + log(out, std::forward(tail)...); + } +}; + + +#endif diff --git a/include/yage/pico_png.hpp b/include/yage/pico_png.hpp new file mode 100644 index 00000000..ef123573 --- /dev/null +++ b/include/yage/pico_png.hpp @@ -0,0 +1,4 @@ +#include +#include + +extern int decodePNG(std::vector &out_image, unsigned long &image_width, unsigned long &image_height, const unsigned char *in_png, size_t in_size, bool convert_to_rgba32 = true); diff --git a/include/yage/resource_manager.hpp b/include/yage/resource_manager.hpp new file mode 100644 index 00000000..155515a3 --- /dev/null +++ b/include/yage/resource_manager.hpp @@ -0,0 +1,18 @@ +#ifndef RESOURCE_MANAGER_HPP +#define RESOURCE_MANAGER_HPP + +#include "gl_texture.hpp" +#include "texture_cache.hpp" + +#include + +class ResourceManager +{ +private: + static TextureCache texture_cache_; +public: + static GlTexture getTexture(const std::string &texture_path); +}; + + +#endif diff --git a/include/yage/sprite.hpp b/include/yage/sprite.hpp new file mode 100644 index 00000000..9f765c7d --- /dev/null +++ b/include/yage/sprite.hpp @@ -0,0 +1,27 @@ +#ifndef SPRITE_HPP +#define SPRITE_HPP + +#include "gl_texture.hpp" + +#include + +#include + +class Sprite +{ +private: + float x_; + float y_; + float width_; + float height_; + GLuint vbo_id_ = 0; + GlTexture texture_; +public: + Sprite(); + ~Sprite(); + + void init(float x, float y, float width, float height, const std::string &texture_path); + void draw(); +}; + +#endif diff --git a/include/yage/texture_cache.hpp b/include/yage/texture_cache.hpp new file mode 100644 index 00000000..44dba2f8 --- /dev/null +++ b/include/yage/texture_cache.hpp @@ -0,0 +1,20 @@ +#ifndef TEXTURE_CACHE_HPP +#define TEXTURE_CACHE_HPP + +#include "gl_texture.hpp" + +#include + +class TextureCache +{ +private: + std::unordered_map texture_map_; +public: + TextureCache(); + ~TextureCache(); + + GlTexture getTexture(const std::string &texture_path); +}; + + +#endif diff --git a/include/yage/vertex.hpp b/include/yage/vertex.hpp new file mode 100644 index 00000000..d9ab1138 --- /dev/null +++ b/include/yage/vertex.hpp @@ -0,0 +1,53 @@ +#ifndef VERTEX_HPP +#define VERTEX_HPP + +#include + +struct Position +{ + float x; + float y; +}; + +struct Color +{ + GLubyte r; + GLubyte g; + GLubyte b; + GLubyte a; +}; + +struct UV +{ + float u; + float v; +}; + +struct Vertex +{ + Position position; + Color color; + UV uv; + + void setPosition(float x, float y) + { + position.x = x; + position.y = y; + } + + void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) + { + color.r = r; + color.g = g; + color.b = b; + color.a = a; + } + + void setUv(float u, float v) + { + uv.u = u; + uv.v = v; + } +}; + +#endif diff --git a/include/yage/window.hpp b/include/yage/window.hpp new file mode 100644 index 00000000..6f3058e9 --- /dev/null +++ b/include/yage/window.hpp @@ -0,0 +1,30 @@ +#ifndef WINDOW_HPP +#define WINDOW_HPP + +#include + +#include + +enum class WindowFlags +{ + SHOWN=0x1, + HIDDEN=0x2, + FULLSCREEN=0x4, + BORDERLESS=0x8, +}; + +class Window +{ +private: + SDL_Window *window_=nullptr; + int width_=1280; + int height_=720; + +public: + Window(); + ~Window(); + + void create(const std::string &window_name, int width, int height, WindowFlags flags=WindowFlags::SHOWN); +}; + +#endif -- cgit