diff options
Diffstat (limited to 'src/libjin/Graphics')
-rw-r--r-- | src/libjin/Graphics/animations/je_animation.h | 2 | ||||
-rw-r--r-- | src/libjin/Graphics/fonts/je_texture_font.h | 4 | ||||
-rw-r--r-- | src/libjin/Graphics/je_canvas.h | 3 | ||||
-rw-r--r-- | src/libjin/Graphics/je_graphic.cpp | 4 | ||||
-rw-r--r-- | src/libjin/Graphics/je_graphic.h | 6 | ||||
-rw-r--r-- | src/libjin/Graphics/je_graphics.h | 2 | ||||
-rw-r--r-- | src/libjin/Graphics/je_image.h | 3 | ||||
-rw-r--r-- | src/libjin/Graphics/je_sprite.cpp | 72 | ||||
-rw-r--r-- | src/libjin/Graphics/je_sprite.h | 11 | ||||
-rw-r--r-- | src/libjin/Graphics/je_texture.h | 3 | ||||
-rw-r--r-- | src/libjin/Graphics/je_window.h | 3 |
11 files changed, 89 insertions, 24 deletions
diff --git a/src/libjin/Graphics/animations/je_animation.h b/src/libjin/Graphics/animations/je_animation.h index 3f9d008..05e1d4f 100644 --- a/src/libjin/Graphics/animations/je_animation.h +++ b/src/libjin/Graphics/animations/je_animation.h @@ -19,7 +19,7 @@ namespace JinEngine class Animation { public: - void onUpdate(float dt); + void update(float dt); void start(); void pause(); diff --git a/src/libjin/Graphics/fonts/je_texture_font.h b/src/libjin/Graphics/fonts/je_texture_font.h index df8f956..8a50699 100644 --- a/src/libjin/Graphics/fonts/je_texture_font.h +++ b/src/libjin/Graphics/fonts/je_texture_font.h @@ -23,7 +23,9 @@ namespace JinEngine /// /// /// - class TextureFont : public Font, public Graphic + class TextureFont + : public Font + , public Graphic { public: diff --git a/src/libjin/Graphics/je_canvas.h b/src/libjin/Graphics/je_canvas.h index 952c25f..3964517 100644 --- a/src/libjin/Graphics/je_canvas.h +++ b/src/libjin/Graphics/je_canvas.h @@ -14,7 +14,8 @@ namespace JinEngine /// /// A canvas is a rendering target. /// - class Canvas: public Graphic + class Canvas + : public Graphic { public: /// diff --git a/src/libjin/Graphics/je_graphic.cpp b/src/libjin/Graphics/je_graphic.cpp index 73d46b3..1231139 100644 --- a/src/libjin/Graphics/je_graphic.cpp +++ b/src/libjin/Graphics/je_graphic.cpp @@ -43,7 +43,7 @@ namespace JinEngine glDeleteTextures(1, &mTexture); } - void Graphic::render(int x, int y, float sx, float sy, float r, float ox, float oy) + void Graphic::render(int x, int y, float sx, float sy, float r, float ox, float oy) const { gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ox, oy); int w = getWidth(), h = getHeight(); @@ -71,7 +71,7 @@ namespace JinEngine gl.bindTexture(0); } - void Graphic::render(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay) + void Graphic::render(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay) const { static float vertexCoords[8]; static float textureCoords[8]; diff --git a/src/libjin/Graphics/je_graphic.h b/src/libjin/Graphics/je_graphic.h index fdc328d..91c8b44 100644 --- a/src/libjin/Graphics/je_graphic.h +++ b/src/libjin/Graphics/je_graphic.h @@ -60,15 +60,15 @@ namespace JinEngine /// /// Render graphic single with given coordinates. /// - void render(int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0); + void render(int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0) const; /// /// Render part of graphic single with given coordinates. /// - void render(const Math::Quad& slice, int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0); + void render(const Math::Quad& slice, int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0) const; protected: - JinEngine::Math::Vector2<uint> mSize; + Math::Vector2<uint> mSize; private: GLuint mTexture; diff --git a/src/libjin/Graphics/je_graphics.h b/src/libjin/Graphics/je_graphics.h index 52bfbda..a46e740 100644 --- a/src/libjin/Graphics/je_graphics.h +++ b/src/libjin/Graphics/je_graphics.h @@ -10,6 +10,7 @@ #include "je_window.h" #include "je_bitmap.h" #include "je_image.h" +#include "je_sprite.h" #include "shaders/je_shader.h" @@ -19,7 +20,6 @@ #include "particles/je_particle_system.h" - //struct Stats //{ // int drawCalls; diff --git a/src/libjin/Graphics/je_image.h b/src/libjin/Graphics/je_image.h index 15baed3..971ac18 100644 --- a/src/libjin/Graphics/je_image.h +++ b/src/libjin/Graphics/je_image.h @@ -13,7 +13,8 @@ namespace JinEngine /// /// Just like bitmap but only from image file. The pixels data is readonly. /// - class Image : public Bitmap + class Image + : public Bitmap { public: /// diff --git a/src/libjin/Graphics/je_sprite.cpp b/src/libjin/Graphics/je_sprite.cpp index 4ef32a4..9ee4fc1 100644 --- a/src/libjin/Graphics/je_sprite.cpp +++ b/src/libjin/Graphics/je_sprite.cpp @@ -12,6 +12,12 @@ namespace JinEngine Sprite::Sprite() : mShader(nullptr) , mGraphic(nullptr) + , mScale(1, 1) + , mColor(255, 255, 255, 255) + { + } + + Sprite::~Sprite() { } @@ -22,37 +28,81 @@ namespace JinEngine void Sprite::setOrigin(Origin origin) { - + int l = 0, r = 0, t = 0, b = 0; + if (mGraphic != nullptr) + { + r = mGraphic->getWidth(); + b = mGraphic->getHeight(); + } + switch (origin) + { + case TopLeft: + mOrigin.x = l; + mOrigin.y = t; + break; + case TopCenter: + mOrigin.x = r/2.f; + mOrigin.y = t; + break; + case TopRight: + mOrigin.x = r; + mOrigin.y = t; + break; + case MiddleLeft: + mOrigin.x = l; + mOrigin.y = b/2.f; + break; + case MiddleCenter: + mOrigin.x = r/2.f; + mOrigin.y = b/2.f; + break; + case MiddleRight: + mOrigin.x = r; + mOrigin.y = b/2.f; + break; + case BottomLeft: + mOrigin.x = l; + mOrigin.y = b; + break; + case BottomCenter: + mOrigin.x = r/2.f; + mOrigin.y = b; + break; + case BottomRight: + mOrigin.x = r; + mOrigin.y = b; + break; + } } void Sprite::setOrigin(int x, int y) { - + mOrigin.set(x, y); } void Sprite::setPosition(int x, int y) { - + mPosition.set(x, y); } void Sprite::setScale(float x, float y) { - + mScale.set(x, y); } void Sprite::setColor(Color color) { - + mColor = color; } - void Sprite::setShader(const Shader* shader) + void Sprite::setShader(Shader* shader) { - + mShader = shader; } void Sprite::setGraphic(const Graphic* graphic) { - + mGraphic = graphic; } void Sprite::render() @@ -60,8 +110,10 @@ namespace JinEngine Shader* shader = Shader::getCurrentShader(); Color c = gl.getColor(); gl.setColor(mColor); - mShader->use(); - mGraphic->render(mPosition.x, mPosition.y, mScale.x, mScale.y, mRotation, mOrigin.x, mOrigin.y); + if(mShader != nullptr) + mShader->use(); + if(mGraphic != nullptr) + mGraphic->render(mPosition.x, mPosition.y, mScale.x, mScale.y, mRotation, mOrigin.x, mOrigin.y); shader->use(); gl.setColor(c); } diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h index 4fb7ebf..fad5b44 100644 --- a/src/libjin/Graphics/je_sprite.h +++ b/src/libjin/Graphics/je_sprite.h @@ -40,9 +40,15 @@ namespace JinEngine void setPosition(int x, int y); void setScale(float x, float y); void setColor(Color color); - void setShader(const Shaders::Shader* shader); + void setShader(Shaders::Shader* shader); void setGraphic(const Graphic* graphic); + float getRotation() { return mRotation; } + const Math::Vector2<float>& getPosition() { return mPosition; } + const Math::Vector2<int>& getOrigin() { return mOrigin; } + const Math::Vector2<float>& getScale() { return mScale; } + const Color& getColor() { return mColor; } + /// /// Render callback. /// @@ -55,10 +61,11 @@ namespace JinEngine Math::Vector2<float> mPosition; Math::Vector2<int> mOrigin; Math::Vector2<float> mScale; + float mRotation; Color mColor; Shaders::Shader* mShader; - Graphic* mGraphic; + const Graphic* mGraphic; }; diff --git a/src/libjin/Graphics/je_texture.h b/src/libjin/Graphics/je_texture.h index 0ab682d..566ba84 100644 --- a/src/libjin/Graphics/je_texture.h +++ b/src/libjin/Graphics/je_texture.h @@ -17,7 +17,8 @@ namespace JinEngine /// /// /// - class Texture: public Graphic + class Texture + : public Graphic { public: /// diff --git a/src/libjin/Graphics/je_window.h b/src/libjin/Graphics/je_window.h index 436fd24..831f3e6 100644 --- a/src/libjin/Graphics/je_window.h +++ b/src/libjin/Graphics/je_window.h @@ -16,7 +16,8 @@ namespace JinEngine /// /// /// - class Window : public Subsystem<Window> + class Window + : public Subsystem<Window> { public: /// |