diff options
Diffstat (limited to 'src/libjin/Graphics')
20 files changed, 127 insertions, 217 deletions
diff --git a/src/libjin/Graphics/Font/je_texture_font.cpp b/src/libjin/Graphics/Font/je_texture_font.cpp index 15d0ace..dcebdb2 100644 --- a/src/libjin/Graphics/Font/je_texture_font.cpp +++ b/src/libjin/Graphics/Font/je_texture_font.cpp @@ -246,7 +246,7 @@ namespace JinEngine } TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) - : GraphicSingle(bitmap) + : Graphic(bitmap) , Font(cellh) { TextureGlyph glyph; @@ -267,7 +267,7 @@ namespace JinEngine } TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) - : GraphicSingle(bitmap) + : Graphic(bitmap) , Font(cellh) { TextureGlyph glyph; diff --git a/src/libjin/Graphics/Font/je_texture_font.h b/src/libjin/Graphics/Font/je_texture_font.h index 5b08747..d61991a 100644 --- a/src/libjin/Graphics/Font/je_texture_font.h +++ b/src/libjin/Graphics/Font/je_texture_font.h @@ -6,7 +6,7 @@ #include "../../math/je_vector4.hpp" -#include "../je_graphic_single.h" +#include "../je_graphic.h" #include "../je_bitmap.h" #include "je_page.h" @@ -21,7 +21,7 @@ namespace JinEngine /// /// /// - class TextureFont : public Font , public GraphicSingle + class TextureFont : public Font , public Graphic { public: diff --git a/src/libjin/Graphics/je_canvas.cpp b/src/libjin/Graphics/je_canvas.cpp index 417127d..7c8e849 100644 --- a/src/libjin/Graphics/je_canvas.cpp +++ b/src/libjin/Graphics/je_canvas.cpp @@ -24,7 +24,7 @@ namespace JinEngine } Canvas::Canvas(int w, int h) - : GraphicSingle(w, h) + : Graphic(w, h) { GLint current_fbo; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); diff --git a/src/libjin/Graphics/je_canvas.h b/src/libjin/Graphics/je_canvas.h index ddfd092..f39b0de 100644 --- a/src/libjin/Graphics/je_canvas.h +++ b/src/libjin/Graphics/je_canvas.h @@ -3,7 +3,7 @@ #include "../core/je_configuration.h" #if defined(jin_graphics) -#include "je_graphic_single.h" +#include "je_graphic.h" namespace JinEngine { @@ -14,7 +14,7 @@ namespace JinEngine /// /// A canvas is a rendering target. /// - class Canvas: public GraphicSingle + class Canvas: public Graphic { public: /// diff --git a/src/libjin/Graphics/je_graphic.cpp b/src/libjin/Graphics/je_graphic.cpp index 86b6bf4..66fb494 100644 --- a/src/libjin/Graphics/je_graphic.cpp +++ b/src/libjin/Graphics/je_graphic.cpp @@ -41,6 +41,67 @@ namespace JinEngine glDeleteTextures(1, &mTexture); } + void Graphic::render(int x, int y, float sx, float sy, float r, float ox, float oy) + { + gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ox, oy); + int w = getWidth(), h = getHeight(); + static float vertexCoords[8]; + static float textureCoords[8]; + // Set vertex coordinates. + vertexCoords[0] = 0; vertexCoords[1] = 0; + vertexCoords[2] = 0; vertexCoords[3] = h; + vertexCoords[4] = w; vertexCoords[5] = h; + vertexCoords[6] = w; vertexCoords[7] = 0; + // Set texture coordinates. + textureCoords[0] = 0; textureCoords[1] = 0; + textureCoords[2] = 0; textureCoords[3] = 1; + textureCoords[4] = 1; textureCoords[5] = 1; + textureCoords[6] = 1; textureCoords[7] = 0; + // Set shader. + Shader* shader = Shader::getCurrentShader(); + shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); + shader->bindVertexPointer(2, GL_FLOAT, 0, vertexCoords); + shader->bindUVPointer(2, GL_FLOAT, 0, textureCoords); + + gl.bindTexture(getGLTexture()); + gl.drawArrays(GL_QUADS, 0, 4); + gl.bindTexture(0); + } + + void Graphic::render(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay) + { + static float vertexCoords[8]; + static float textureCoords[8]; + + // Set vertex coordinates. + vertexCoords[0] = 0; vertexCoords[1] = 0; + vertexCoords[2] = 0; vertexCoords[3] = slice.h; + vertexCoords[4] = slice.w; vertexCoords[5] = slice.h; + vertexCoords[6] = slice.w; vertexCoords[7] = 0; + // Set texture coordinates. + float slx = slice.x / mSize.w; + float sly = slice.y / mSize.h; + float slw = slice.w / mSize.w; + float slh = slice.h / mSize.h; + textureCoords[0] = slx; textureCoords[1] = sly; + textureCoords[2] = slx; textureCoords[3] = sly + slh; + textureCoords[4] = slx + slw; textureCoords[5] = sly + slh; + textureCoords[6] = slx + slw; textureCoords[7] = sly; + + gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ax, ay); + + Shader* shader = Shader::getCurrentShader(); + shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); + shader->bindVertexPointer(2, GL_FLOAT, 0, vertexCoords); + shader->bindUVPointer(2, GL_FLOAT, 0, textureCoords); + + gl.bindTexture(getGLTexture()); + gl.drawArrays(GL_QUADS, 0, 4); + gl.bindTexture(0); + } + //void Graphic::setFilter(GLint min, GLint max) //{ // glTexParameteri(GL_) diff --git a/src/libjin/Graphics/je_graphic.h b/src/libjin/Graphics/je_graphic.h index 2ed028d..69fa109 100644 --- a/src/libjin/Graphics/je_graphic.h +++ b/src/libjin/Graphics/je_graphic.h @@ -14,12 +14,6 @@ namespace JinEngine namespace Graphics { - // - // Graphic - // |- GraphicSingle - // |- GraphicBatch - // - /// /// Class inherites Graphic doesn't keep any state such as origin, scale and other properties. /// @@ -63,6 +57,16 @@ namespace JinEngine /// void setFilter(GLint min, GLint max); + /// + /// 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); + + /// + /// 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); + protected: JinEngine::Math::Vector2<uint> mSize; diff --git a/src/libjin/Graphics/je_graphic_batch.cpp b/src/libjin/Graphics/je_graphic_batch.cpp deleted file mode 100644 index 1b8601a..0000000 --- a/src/libjin/Graphics/je_graphic_batch.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "je_graphic_batch.h" - -namespace JinEngine -{ - namespace Graphics - { - - - - } // namespace Graphics -} // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/Graphics/je_graphic_batch.h b/src/libjin/Graphics/je_graphic_batch.h deleted file mode 100644 index 274ce4d..0000000 --- a/src/libjin/Graphics/je_graphic_batch.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __JE_GRAPHIC_BATCH_H -#define __JE_GRAPHIC_BATCH_H - -#include "je_graphic_single.h" - -namespace JinEngine -{ - namespace Graphics - { - - // - // GraphicsBatch - // - - /// - /// For reducing draw call. Draw a bunch of graphic. - /// - class GraphicBatch : public GraphicSingle - { - public: - void add(int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0); - - private: - - - }; - - } // namespace Graphics -} // namespace JinEngine - -#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/je_graphic_sheet.cpp b/src/libjin/Graphics/je_graphic_manager.cpp index e69de29..e69de29 100644 --- a/src/libjin/Graphics/je_graphic_sheet.cpp +++ b/src/libjin/Graphics/je_graphic_manager.cpp diff --git a/src/libjin/Graphics/je_graphic_manager.h b/src/libjin/Graphics/je_graphic_manager.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/je_graphic_manager.h diff --git a/src/libjin/Graphics/je_graphic_sheet.h b/src/libjin/Graphics/je_graphic_sheet.h deleted file mode 100644 index 72c038f..0000000 --- a/src/libjin/Graphics/je_graphic_sheet.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __JE_GRAPHIC_SHEET -#define __JE_GRAPHIC_SHEET - -#include "je_graphic.h" - -namespace JinEngine -{ - namespace Graphics - { - - /// - /// A graphic sheet is a atlas. - /// - class GraphicSheet : public Graphic - { - - }; - - } // namespace Graphics -} // namespace JinEngine - -#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/je_graphic_single.cpp b/src/libjin/Graphics/je_graphic_single.cpp deleted file mode 100644 index 96eb1af..0000000 --- a/src/libjin/Graphics/je_graphic_single.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "shader/je_shader.h" - -#include "je_graphic_single.h" - -namespace JinEngine -{ - namespace Graphics - { - - GraphicSingle::GraphicSingle(int w, int h) - : Graphic(w, h) - { - } - - GraphicSingle::GraphicSingle(const Bitmap* bitmap) - : Graphic(bitmap) - { - } - - void GraphicSingle::render(int x, int y, float sx, float sy, float r, float ox, float oy) - { - gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ox, oy); - int w = getWidth(), h = getHeight(); - static float vertexCoords[8]; - static float textureCoords[8]; - // Set vertex coordinates. - vertexCoords[0] = 0; vertexCoords[1] = 0; - vertexCoords[2] = 0; vertexCoords[3] = h; - vertexCoords[4] = w; vertexCoords[5] = h; - vertexCoords[6] = w; vertexCoords[7] = 0; - // Set texture coordinates. - textureCoords[0] = 0; textureCoords[1] = 0; - textureCoords[2] = 0; textureCoords[3] = 1; - textureCoords[4] = 1; textureCoords[5] = 1; - textureCoords[6] = 1; textureCoords[7] = 0; - // Set shader. - Shader* shader = Shader::getCurrentShader(); - shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); - shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); - shader->bindVertexPointer(2, GL_FLOAT, 0, vertexCoords); - shader->bindUVPointer(2, GL_FLOAT, 0, textureCoords); - - gl.bindTexture(getGLTexture()); - gl.drawArrays(GL_QUADS, 0, 4); - gl.bindTexture(0); - } - - void GraphicSingle::render(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay) - { - static float vertexCoords[8]; - static float textureCoords[8]; - - // Set vertex coordinates. - vertexCoords[0] = 0; vertexCoords[1] = 0; - vertexCoords[2] = 0; vertexCoords[3] = slice.h; - vertexCoords[4] = slice.w; vertexCoords[5] = slice.h; - vertexCoords[6] = slice.w; vertexCoords[7] = 0; - // Set texture coordinates. - float slx = slice.x / mSize.w; - float sly = slice.y / mSize.h; - float slw = slice.w / mSize.w; - float slh = slice.h / mSize.h; - textureCoords[0] = slx; textureCoords[1] = sly; - textureCoords[2] = slx; textureCoords[3] = sly + slh; - textureCoords[4] = slx + slw; textureCoords[5] = sly + slh; - textureCoords[6] = slx + slw; textureCoords[7] = sly; - - gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ax, ay); - - Shader* shader = Shader::getCurrentShader(); - shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); - shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); - shader->bindVertexPointer(2, GL_FLOAT, 0, vertexCoords); - shader->bindUVPointer(2, GL_FLOAT, 0, textureCoords); - - gl.bindTexture(getGLTexture()); - gl.drawArrays(GL_QUADS, 0, 4); - gl.bindTexture(0); - } - - } // namespace Graphics -} // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/Graphics/je_graphic_single.h b/src/libjin/Graphics/je_graphic_single.h deleted file mode 100644 index f61234b..0000000 --- a/src/libjin/Graphics/je_graphic_single.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __JE_GRAPHIC_SINGLE_H -#define __JE_GRAPHIC_SINGLE_H - -#include "../math/je_quad.h" - -#include "je_graphic.h" - -namespace JinEngine -{ - namespace Graphics - { - // - // GraphicSingle - // |- Canvas - // |- Texture - // |- TextureFont - // - - /// - /// Single graphic, comparing to graphics batch, a single graphic need assign it's vertex and screen uv. - /// For example, a texture and canvas should be a graphic single. - /// - class GraphicSingle : public Graphic - { - public: - /// - /// - /// - GraphicSingle(const Bitmap* bitmap); - - /// - /// - /// - GraphicSingle(int w = 0, int h = 0); - - /// - /// 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); - - /// - /// 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); - - private: - - }; - - } // namespace Graphics -} // namespace JinEngine - -#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h index df8d6eb..730e11e 100644 --- a/src/libjin/Graphics/je_sprite.h +++ b/src/libjin/Graphics/je_sprite.h @@ -28,7 +28,7 @@ namespace JinEngine /// /// Render callback. /// - void onRender(); + virtual void onRender(); private: /// @@ -39,7 +39,7 @@ namespace JinEngine Math::Vector2<float> mScale; Color mColor; Shader* mShader; - GraphicSingle* mGraphic; + Graphic* mGraphic; }; diff --git a/src/libjin/Graphics/je_sprite_batch.cpp b/src/libjin/Graphics/je_sprite_batch.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/je_sprite_batch.cpp diff --git a/src/libjin/Graphics/je_sprite_batch.h b/src/libjin/Graphics/je_sprite_batch.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/je_sprite_batch.h diff --git a/src/libjin/Graphics/je_sprite_sheet.cpp b/src/libjin/Graphics/je_sprite_sheet.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/je_sprite_sheet.cpp diff --git a/src/libjin/Graphics/je_sprite_sheet.h b/src/libjin/Graphics/je_sprite_sheet.h new file mode 100644 index 0000000..29f3a0e --- /dev/null +++ b/src/libjin/Graphics/je_sprite_sheet.h @@ -0,0 +1,44 @@ +#ifndef __JE_SPRITE_SHEET_H +#define __JE_SPRITE_SHEET_H + +#include <vector> + +#include "../math/je_quad.h" + +#include "je_sprite.h" + +namespace JinEngine +{ + namespace Graphics + { + + class SpriteSheet + { + public: + /// + /// Create a new sprite in sheet. + /// + Sprite* createSprite(const Math::Quad& quad); + + private: + class SpriteInSheet : public Sprite + { + public: + + private: + /// + /// Quad in sprite sheet. + /// + Math::Quad quad; + + }; + + std::vector<SpriteInSheet> mSprites; + Graphic* mGraphic; + + }; + + } // namespace Graphics +} // namespace JinEngine + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/je_texture.cpp b/src/libjin/Graphics/je_texture.cpp index ff07748..8aa3f9a 100644 --- a/src/libjin/Graphics/je_texture.cpp +++ b/src/libjin/Graphics/je_texture.cpp @@ -30,7 +30,7 @@ namespace JinEngine } Texture::Texture(const Bitmap* bitmap) - : GraphicSingle(bitmap) + : Graphic(bitmap) { } diff --git a/src/libjin/Graphics/je_texture.h b/src/libjin/Graphics/je_texture.h index dff3f40..e47ad58 100644 --- a/src/libjin/Graphics/je_texture.h +++ b/src/libjin/Graphics/je_texture.h @@ -6,7 +6,7 @@ #include "GLee/GLee.h" #include "je_color.h" -#include "je_graphic_single.h" +#include "je_graphic.h" #include "je_bitmap.h" namespace JinEngine @@ -17,7 +17,7 @@ namespace JinEngine /// /// /// - class Texture: public GraphicSingle + class Texture: public Graphic { public: /// |