diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-04 21:47:16 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-04 21:47:16 +0100 |
commit | 905f72775fa91b0a467f3c0847c60cf0f85a6d80 (patch) | |
tree | 5aa86baf8ed06fd4af036d0bb6c0dbefb5498f9f /include | |
parent | 55a1e0ad7c9d2661c266b2e767bfcb2f944e859f (diff) | |
download | YAGE-905f72775fa91b0a467f3c0847c60cf0f85a6d80.tar.gz YAGE-905f72775fa91b0a467f3c0847c60cf0f85a6d80.zip |
Sprite batching workin
Diffstat (limited to 'include')
-rw-r--r-- | include/YAGE/camera2d.hpp | 10 | ||||
-rw-r--r-- | include/YAGE/inputmanager.hpp | 23 | ||||
-rw-r--r-- | include/YAGE/spritebatch.hpp | 67 | ||||
-rw-r--r-- | include/YAGE/window.hpp | 2 |
4 files changed, 83 insertions, 19 deletions
diff --git a/include/YAGE/camera2d.hpp b/include/YAGE/camera2d.hpp index 030b0a37..0c86fc31 100644 --- a/include/YAGE/camera2d.hpp +++ b/include/YAGE/camera2d.hpp @@ -9,21 +9,23 @@ namespace yage class Camera2D { + // member variables private: bool matrix_needs_update_=true; float scale_=1.f; glm::vec2 position_; glm::mat4 camera_matrix_; glm::mat4 ortho_matrix_; + + // member functions public: Camera2D(int screen_width=1280, int screen_height=720); virtual ~Camera2D(); + // update camera location 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; } + // camera movement + void move(const glm::vec2 &direction); // getters float getScale() { return scale_; } diff --git a/include/YAGE/inputmanager.hpp b/include/YAGE/inputmanager.hpp new file mode 100644 index 00000000..7f49c3b3 --- /dev/null +++ b/include/YAGE/inputmanager.hpp @@ -0,0 +1,23 @@ +#ifndef INPUT_MANAGER_HPP +#define INPUT_MANAGER_HPP + +#include <unordered_map> + +namespace yage +{ + +class InputManager +{ + // member variables +private: + std::unordered_map<unsigned, bool> key_map_; + + // member functions +public: + void keyPressed(unsigned key); + void keyReleased(unsigned key); + bool isKeyPressed(unsigned key) const; +}; + +} +#endif diff --git a/include/YAGE/spritebatch.hpp b/include/YAGE/spritebatch.hpp index fcc6faec..3f40a009 100644 --- a/include/YAGE/spritebatch.hpp +++ b/include/YAGE/spritebatch.hpp @@ -11,39 +11,76 @@ namespace yage { -struct Glyph +class Glyph { - GLuint texture; - float depth; - - Vertex top_left; - Vertex top_right; - Vertex bottom_right; - Vertex bottom_left; + // member variables +private: + GLuint texture_; + float depth_; + Vertex top_left_; + Vertex top_right_; + Vertex bottom_right_; + Vertex bottom_left_; + + // member functions +public: + Glyph(GLuint texture, float depth, const Vertex &top_left, const Vertex &top_right, const Vertex &bottom_right, const Vertex &bottom_left); + + inline GLuint texture() const { return texture_; } + inline float depth() const { return depth_; } + inline Vertex top_left() const { return top_left_; } + inline Vertex top_right() const { return top_right_; } + inline Vertex bottom_right() const { return bottom_right_; } + inline Vertex bottom_left() const { return bottom_left_; } +}; + +class RenderBatch +{ + // member variables +public: + GLint offset_; +private: + GLsizei num_vertices_; + GLuint texture_; + + // member functions +public: + RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture); + + // getters + inline GLint offset() const { return offset_; } + inline GLsizei num_vertices() const { return num_vertices_; } + inline GLuint texture() const { return texture_; } }; class SpriteBatch { -public: // member variables + // member variables +public: + static const int NUM_VERTICES=6; private: GLuint vbo_=0; GLuint vao_=0; - std::vector<Glyph> glyphs_; std::vector<Glyph *> glyph_ptrs_; - -public: // member functions + std::vector<RenderBatch> render_batches_; + + // member functions +public: SpriteBatch(); ~SpriteBatch(); + // initialize vaos and vbos + void init(); void begin(); void end(); - + // adds a sprite to the sprite batch to be rendered later void draw(const glm::vec4 &destination_rect, const glm::vec4 &uv_rect, GLuint texture, const Color &color, float depth); - - void renderBatch(); + // render the batch + void render(); private: void createVertexArray(); + void createRenderBatches(); void sortGlyphs(); }; diff --git a/include/YAGE/window.hpp b/include/YAGE/window.hpp index 5f104912..d86c00ac 100644 --- a/include/YAGE/window.hpp +++ b/include/YAGE/window.hpp @@ -34,6 +34,8 @@ public: // member functions void create(const std::string &window_name, int width, int height, unsigned flags=WindowFlags::SHOWN); // swap the buffer void swapBuffer(); + // clear buffer + void clearBuffer(); private: }; |