aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-04-02 09:15:30 +0100
committerYann Herklotz <ymherklotz@gmail.com>2017-04-02 09:15:30 +0100
commit21a147c3c1c2fad2819fe76becab320c51eb131f (patch)
tree9114123be1d9165a199d8b27af8f9b4e00333e71 /include
downloadYAGE-21a147c3c1c2fad2819fe76becab320c51eb131f.tar.gz
YAGE-21a147c3c1c2fad2819fe76becab320c51eb131f.zip
Adding initial files
Diffstat (limited to 'include')
-rw-r--r--include/yage/gl_texture.hpp13
-rw-r--r--include/yage/glsl_program.hpp33
-rw-r--r--include/yage/image_loader.hpp15
-rw-r--r--include/yage/io_manager.hpp14
-rw-r--r--include/yage/logger.hpp24
-rw-r--r--include/yage/pico_png.hpp4
-rw-r--r--include/yage/resource_manager.hpp18
-rw-r--r--include/yage/sprite.hpp27
-rw-r--r--include/yage/texture_cache.hpp20
-rw-r--r--include/yage/vertex.hpp53
-rw-r--r--include/yage/window.hpp30
11 files changed, 251 insertions, 0 deletions
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 <GL/glew.h>
+
+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 <GL/glew.h>
+
+#include <string>
+
+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 <string>
+
+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 <string>
+#include <vector>
+
+class IoManager
+{
+public:
+ static bool readFileToBuffer(const std::string &file_path, std::vector<unsigned char> &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 <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/pico_png.hpp
new file mode 100644
index 00000000..ef123573
--- /dev/null
+++ b/include/yage/pico_png.hpp
@@ -0,0 +1,4 @@
+#include <vector>
+#include <cstdlib>
+
+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);
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 <string>
+
+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 <GL/glew.h>
+
+#include <string>
+
+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 <unordered_map>
+
+class TextureCache
+{
+private:
+ std::unordered_map<std::string, GlTexture> 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 <GL/glew.h>
+
+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 <SDL2/SDL.h>
+
+#include <string>
+
+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