aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Graphics')
-rw-r--r--src/libjin/Graphics/Font/je_decoder.h6
-rw-r--r--src/libjin/Graphics/Font/je_font.h1
-rw-r--r--src/libjin/Graphics/Font/je_text.cpp8
-rw-r--r--src/libjin/Graphics/Font/je_text.h94
-rw-r--r--src/libjin/Graphics/Font/je_texture_font.h77
-rw-r--r--src/libjin/Graphics/Font/je_ttf.h156
-rw-r--r--src/libjin/Graphics/Shader/je_jsl_compiler.cpp11
-rw-r--r--src/libjin/Graphics/Shader/je_jsl_compiler.h27
-rw-r--r--src/libjin/Graphics/Shader/je_shader.cpp12
-rw-r--r--src/libjin/Graphics/animation/je_animation.cpp0
-rw-r--r--src/libjin/Graphics/animation/je_animation.h17
-rw-r--r--src/libjin/Graphics/animation/je_clip.cpp0
-rw-r--r--src/libjin/Graphics/animation/je_clip.h17
-rw-r--r--src/libjin/Graphics/je_bitmap.h2
-rw-r--r--src/libjin/Graphics/je_canvas.h1
-rw-r--r--src/libjin/Graphics/je_color.h8
-rw-r--r--src/libjin/Graphics/je_drawable.cpp78
-rw-r--r--src/libjin/Graphics/je_drawable.h23
-rw-r--r--src/libjin/Graphics/je_gl.h10
-rw-r--r--src/libjin/Graphics/je_image.cpp8
-rw-r--r--src/libjin/Graphics/je_mesh.cpp2
-rw-r--r--src/libjin/Graphics/je_mesh.h3
-rw-r--r--src/libjin/Graphics/je_shapes.h9
-rw-r--r--src/libjin/Graphics/je_sprite.cpp11
-rw-r--r--src/libjin/Graphics/je_sprite.h16
-rw-r--r--src/libjin/Graphics/je_sprite_batch.cpp0
-rw-r--r--src/libjin/Graphics/je_sprite_batch.h17
-rw-r--r--src/libjin/Graphics/je_window.cpp10
-rw-r--r--src/libjin/Graphics/je_window.h1
-rw-r--r--src/libjin/Graphics/particle/je_particle.cpp0
-rw-r--r--src/libjin/Graphics/particle/je_particle.h20
-rw-r--r--src/libjin/Graphics/particle/je_particle_batch.cpp0
-rw-r--r--src/libjin/Graphics/particle/je_particle_batch.h0
-rw-r--r--src/libjin/Graphics/particle/je_particle_emitter.cpp0
-rw-r--r--src/libjin/Graphics/particle/je_particle_emitter.h0
-rw-r--r--src/libjin/Graphics/particle/je_particle_system.cpp1
-rw-r--r--src/libjin/Graphics/particle/je_particle_system.h0
37 files changed, 563 insertions, 83 deletions
diff --git a/src/libjin/Graphics/Font/je_decoder.h b/src/libjin/Graphics/Font/je_decoder.h
index 162f22e..36cbda7 100644
--- a/src/libjin/Graphics/Font/je_decoder.h
+++ b/src/libjin/Graphics/Font/je_decoder.h
@@ -16,6 +16,7 @@ namespace JinEngine
class Decoder
{
public:
+
///
/// Decode a code unit.
///
@@ -32,6 +33,7 @@ namespace JinEngine
/// @return Next code unit location.
///
virtual const void* next(const void* data) const = 0;
+
};
///
@@ -40,6 +42,7 @@ namespace JinEngine
class Utf8 : public Decoder
{
public:
+
///
/// Decode a code unit.
///
@@ -56,6 +59,7 @@ namespace JinEngine
/// @return Next code unit location.
///
const void* next(const void* data) const override;
+
};
///
@@ -64,6 +68,7 @@ namespace JinEngine
class Ascii : public Decoder
{
public:
+
///
/// Decode a code unit.
///
@@ -80,6 +85,7 @@ namespace JinEngine
/// @return Next code unit location.
///
const void* next(const void* data) const override;
+
};
} // namespace Graphics
diff --git a/src/libjin/Graphics/Font/je_font.h b/src/libjin/Graphics/Font/je_font.h
index ec60c21..75dd4c5 100644
--- a/src/libjin/Graphics/Font/je_font.h
+++ b/src/libjin/Graphics/Font/je_font.h
@@ -89,6 +89,7 @@ namespace JinEngine
inline unsigned getFontSize() { return mFontSize; };
protected:
+
unsigned mFontSize;
};
diff --git a/src/libjin/Graphics/Font/je_text.cpp b/src/libjin/Graphics/Font/je_text.cpp
index 70a1c36..75dfc7b 100644
--- a/src/libjin/Graphics/Font/je_text.cpp
+++ b/src/libjin/Graphics/Font/je_text.cpp
@@ -20,8 +20,8 @@ namespace JinEngine
{
switch (encode)
{
- case Encode::UTF8: decoder = new Utf8(); break;
- case Encode::ASCII: decoder = new Ascii(); break;
+ case Encode::UTF8: decoder = new Utf8(); break;
+ case Encode::ASCII: decoder = new Ascii(); break;
}
}
@@ -33,8 +33,8 @@ namespace JinEngine
{
switch (encode)
{
- case Encode::UTF8: decoder = new Utf8(); break;
- case Encode::ASCII: decoder = new Ascii(); break;
+ case Encode::UTF8: decoder = new Utf8(); break;
+ case Encode::ASCII: decoder = new Ascii(); break;
}
}
diff --git a/src/libjin/Graphics/Font/je_text.h b/src/libjin/Graphics/Font/je_text.h
index af40993..7436875 100644
--- a/src/libjin/Graphics/Font/je_text.h
+++ b/src/libjin/Graphics/Font/je_text.h
@@ -31,44 +31,134 @@ namespace JinEngine
class Text
{
public:
+ ///
+ ///
+ ///
Text(Encode encode, const void* data);
+
+ ///
+ ///
+ ///
Text(Encode encode, const void* data, unsigned int length);
+
+ ///
+ ///
+ ///
~Text();
+ ///
+ ///
+ ///
const Content& getContent() const;
+
+ ///
+ ///
+ ///
const Content& operator*() const;
private:
+ ///
+ ///
+ ///
class Iterator
{
public:
+
+ ///
+ ///
+ ///
Iterator(const Iterator& itor);
+
+ ///
+ ///
+ ///
Iterator(const Encode& encode, const void* data, unsigned int length);
+
+ ///
+ ///
+ ///
~Iterator();
+ ///
+ ///
+ ///
Codepoint get();
+
//Iterator begin();
//Iterator end();
+
+ ///
+ ///
+ ///
void toBegin();
+
+ ///
+ ///
+ ///
void toEnd();
+
+ ///
+ ///
+ ///
Codepoint operator *();
- /* prefix ++ */
+
+ ///
+ ///
+ ///
Iterator& operator ++();
- /* postfix ++ */
+
+ ///
+ ///
+ ///
Iterator operator ++(int);
+
+ ///
+ ///
+ ///
bool operator !=(const Iterator& itor);
+
+ ///
+ ///
+ ///
bool operator ==(const Iterator& itor);
private:
+
+ ///
+ ///
+ ///
void operator = (const Iterator&);
+ ///
+ ///
+ ///
const Encode encode;
+
+ ///
+ ///
+ ///
const Decoder* decoder;
+
+ ///
+ ///
+ ///
const void* p;
+
+ ///
+ ///
+ ///
const void* const data;
+
+ ///
+ ///
+ ///
unsigned int length;
+
};
+ ///
+ ///
+ ///
Content content;
};
diff --git a/src/libjin/Graphics/Font/je_texture_font.h b/src/libjin/Graphics/Font/je_texture_font.h
index 9805cda..43d92c8 100644
--- a/src/libjin/Graphics/Font/je_texture_font.h
+++ b/src/libjin/Graphics/Font/je_texture_font.h
@@ -25,36 +25,111 @@ namespace JinEngine
, public Drawable
{
public:
+
+ ///
+ ///
+ ///
static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh);
+
+ ///
+ ///
+ ///
static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh);
+
+ ///
+ ///
+ ///
static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh);
+
+ ///
+ ///
+ ///
static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh);
-
+
+ ///
+ ///
+ ///
~TextureFont();
+ ///
+ ///
+ ///
Page* typeset(const Text& text, int lineheight, int spacing = 0) override;
+
+ ///
+ ///
+ ///
Page* typeset(const Content& text, int lineheight, int spacing = 0) override ;
+ ///
+ ///
+ ///
void print(const Page* page, int x, int y) override;
+
+ ///
+ ///
+ ///
void print(const Content& text, int x, int y, int linehgiht, int spacing = 0) override;
+
+ ///
+ ///
+ ///
void print(const Text& text, int x, int y, int lineheight, int spacing = 0)override;
private:
+
+ ///
+ ///
+ ///
struct TextureGlyph
{
float x, y, w, h;
};
+ ///
+ ///
+ ///
TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh);
+
+ ///
+ ///
+ ///
TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh);
+ ///
+ ///
+ ///
int getCharWidth(int c);
+
+ ///
+ ///
+ ///
int getCharHeight(int c);
+
+ ///
+ ///
+ ///
int getTextWidth(const Content& text, int spacing = 0);
+
+ ///
+ ///
+ ///
int getTextHeight(const Content& text, int lineheight);
+
+ ///
+ ///
+ ///
void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0);
+
+ ///
+ ///
+ ///
const TextureGlyph* findGlyph(Codepoint codepoint) const;
+
+ ///
+ ///
+ ///
std::map<Codepoint, TextureGlyph> glyphs;
};
diff --git a/src/libjin/Graphics/Font/je_ttf.h b/src/libjin/Graphics/Font/je_ttf.h
index e4314fe..9acb07e 100644
--- a/src/libjin/Graphics/Font/je_ttf.h
+++ b/src/libjin/Graphics/Font/je_ttf.h
@@ -34,32 +34,81 @@ namespace JinEngine
class TTFData
{
public:
+
+ ///
+ ///
+ ///
static TTFData* createTTFData(const unsigned char* data, unsigned int size);
+ ///
+ ///
+ ///
~TTFData();
+ ///
+ ///
+ ///
TTF* createTTF(unsigned ttfsize);
+ ///
+ ///
+ ///
void pushTTFsize(unsigned ttfsize);
+
+ ///
+ ///
+ ///
void popTTFsize();
+ ///
+ ///
+ ///
Channel* getCodepointBitmapAlpha(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const;
+
+ ///
+ ///
+ ///
Color* getCodepointBitmap(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const;
+ ///
+ ///
+ ///
void getVMetrics(int* baseline, int* descent);
+
+ ///
+ ///
+ ///
void getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing);
private:
+
+ ///
+ ///
+ ///
static const unsigned int FONT_SIZE = 12;
+ ///
+ ///
+ ///
TTFData(const unsigned char* data, unsigned int size);
+ ///
+ ///
+ ///
stbtt_fontinfo info;
+
+ ///
+ ///
+ ///
struct
{
unsigned char* data;
unsigned int size;
} raw;
+
+ ///
+ ///
+ ///
std::vector<float> scales;
};
@@ -69,18 +118,43 @@ namespace JinEngine
public:
//static TTF* createTTF(TTFData* ttfData, unsigned ttfSzie);
+ ///
+ ///
+ ///
Page* typeset(const Text& text, int lineheight, int spacing = 0) override;
+
+ ///
+ ///
+ ///
Page* typeset(const Content& text, int lineheight, int spacing = 0) override;
+ ///
+ ///
+ ///
void print(const Text& text, int x, int y, int lineheight, int spacing = 0) override;
+
+ ///
+ ///
+ ///
void print(const Content& text, int x, int y, int lineheight, int spacing = 0) override;
+
+ ///
+ ///
+ ///
void print(const Page* page, int x, int y) override;
+ ///
+ ///
+ ///
~TTF();
private:
+
friend class TTFData;
+ ///
+ ///
+ ///
struct TTFGlyph
{
GLuint atlas;
@@ -94,34 +168,114 @@ namespace JinEngine
unsigned int width, height;
};
+ ///
+ ///
+ ///
static const int TEXTURE_SIZE_LEVELS_COUNT = 7;
+
+ ///
+ ///
+ ///
static const int TEXTURE_SIZE_LEVEL_MAX = TEXTURE_SIZE_LEVELS_COUNT - 1;
+
+ ///
+ ///
+ ///
static const int TEXTURE_WIDTHS[TEXTURE_SIZE_LEVELS_COUNT];
+
+ ///
+ ///
+ ///
static const int TEXTURE_HEIGHTS[TEXTURE_SIZE_LEVELS_COUNT];
+ ///
+ ///
+ ///
TTF(TTFData* ttf, Codepoint ttfSize);
+ ///
+ ///
+ ///
void estimateSize();
+
+ ///
+ ///
+ ///
GLuint createAtlas();
+
+ ///
+ ///
+ ///
TTFGlyph& bakeGlyph(Codepoint character);
+
+ ///
+ ///
+ ///
TTFGlyph& findGlyph(Codepoint character);
+ ///
+ ///
+ ///
int getCharWidth(int c);
+
+ ///
+ ///
+ ///
int getCharHeight(int c);
+ ///
+ ///
+ ///
int getTextWidth(const Content& text, int spacing = 0);
+
+ ///
+ ///
+ ///
int getTextHeight(const Content& text, int lineheight);
+
+ ///
+ ///
+ ///
void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0);
+ ///
+ ///
+ ///
int textureWidth;
+
+ ///
+ ///
+ ///
int textureHeight;
+
+ ///
+ ///
+ ///
std::vector<GLuint> atlases;
+
+ ///
+ ///
+ ///
std::map<Codepoint, TTFGlyph> glyphs;
+
+ ///
+ ///
+ ///
TTFData* ttf;
+
+ ///
+ ///
+ ///
int baseline;
+
+ ///
+ ///
+ ///
int descent;
- /* cursor helped render to texture */
+ ///
+ ///
+ ///
Math::Vector2<float> cursor;
};
diff --git a/src/libjin/Graphics/Shader/je_jsl_compiler.cpp b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp
new file mode 100644
index 0000000..490caea
--- /dev/null
+++ b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp
@@ -0,0 +1,11 @@
+#include "je_jsl_compiler.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+
+
+ } // namespace Graphics
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/Shader/je_jsl_compiler.h b/src/libjin/Graphics/Shader/je_jsl_compiler.h
new file mode 100644
index 0000000..b530466
--- /dev/null
+++ b/src/libjin/Graphics/Shader/je_jsl_compiler.h
@@ -0,0 +1,27 @@
+#ifndef __JE_JSL_COMPILER_H
+#define __JE_JSL_COMPILER_H
+
+#include "../../common/je_singleton.hpp"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+ ///
+ /// Compile JSL into GLSL.
+ ///
+ class JSLCompiler : public Singleton<JSLCompiler>
+ {
+ public:
+
+
+ private:
+ singleton(JSLCompiler);
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/Shader/je_shader.cpp b/src/libjin/Graphics/Shader/je_shader.cpp
index 19485b9..6066864 100644
--- a/src/libjin/Graphics/Shader/je_shader.cpp
+++ b/src/libjin/Graphics/Shader/je_shader.cpp
@@ -77,6 +77,8 @@ namespace JinEngine
{
if (CurrentShader == this)
unuse();
+ // delete shader program
+ glDeleteShader(mPID);
}
bool Shader::compile(const string& program)
@@ -96,21 +98,23 @@ namespace JinEngine
int start = loc_VERTEX_SHADER + strlen("#VERTEX_SHADER");
string vertex_shader = program.substr(start, loc_END_VERTEX_SHADER - start);
Buffer vbuffer = Buffer(vertex_shader.length() + BASE_VERTEX_SHADER_SIZE);
- formatVertexShader((char*)vbuffer.data, vertex_shader.c_str());
+ formatVertexShader((char*)&vbuffer, vertex_shader.c_str());
start = loc_FRAGMENT_SHADER + strlen("#FRAGMENT_SHADER");
string fragment_shader = program.substr(start, loc_END_FRAGMENT_SHADER - start);
Buffer fbuffer = Buffer(fragment_shader.length() + BASE_FRAGMENT_SHADER_SIZE);
- formatFragmentShader((char*)fbuffer.data, fragment_shader.c_str());
+ formatFragmentShader((char*)&fbuffer, fragment_shader.c_str());
// compile
GLint success;
GLuint vshader = glCreateShader(GL_VERTEX_SHADER);
- glShaderSource(vshader, 1, (const GLchar**)&vbuffer.data, NULL);
+ const byte* _data = &vbuffer;
+ glShaderSource(vshader, 1, (const GLchar**)&_data, NULL);
glCompileShader(vshader);
glGetShaderiv(vshader, GL_COMPILE_STATUS, &success);
if (success == GL_FALSE)
return false;
GLuint fshader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fshader, 1, (const GLchar**)&fbuffer.data, NULL);
+ _data = &fbuffer;
+ glShaderSource(fshader, 1, (const GLchar**)&_data, NULL);
glCompileShader(fshader);
glGetShaderiv(fshader, GL_COMPILE_STATUS, &success);
if (success == GL_FALSE)
diff --git a/src/libjin/Graphics/animation/je_animation.cpp b/src/libjin/Graphics/animation/je_animation.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/animation/je_animation.cpp
diff --git a/src/libjin/Graphics/animation/je_animation.h b/src/libjin/Graphics/animation/je_animation.h
new file mode 100644
index 0000000..c006f83
--- /dev/null
+++ b/src/libjin/Graphics/animation/je_animation.h
@@ -0,0 +1,17 @@
+#ifndef __JE_ANIMATION_H
+#define __JE_ANIMATION_H
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+ class Animation
+ {
+
+ };
+
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/animation/je_clip.cpp b/src/libjin/Graphics/animation/je_clip.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/animation/je_clip.cpp
diff --git a/src/libjin/Graphics/animation/je_clip.h b/src/libjin/Graphics/animation/je_clip.h
new file mode 100644
index 0000000..35a35b3
--- /dev/null
+++ b/src/libjin/Graphics/animation/je_clip.h
@@ -0,0 +1,17 @@
+#ifndef __JE_CLIP_H
+#define __JE_CLIP_H
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+ class Clip
+ {
+
+ };
+
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/je_bitmap.h b/src/libjin/Graphics/je_bitmap.h
index 8adc326..d9d0981 100644
--- a/src/libjin/Graphics/je_bitmap.h
+++ b/src/libjin/Graphics/je_bitmap.h
@@ -4,7 +4,9 @@
#if LIBJIN_MODULES_RENDER
#include "../3rdparty/GLee/GLee.h"
+#include "../common/je_types.h"
#include "../math/je_vector2.hpp"
+
#include "je_color.h"
namespace JinEngine
diff --git a/src/libjin/Graphics/je_canvas.h b/src/libjin/Graphics/je_canvas.h
index 321cd32..9839899 100644
--- a/src/libjin/Graphics/je_canvas.h
+++ b/src/libjin/Graphics/je_canvas.h
@@ -64,4 +64,5 @@ namespace JinEngine
} // namespace JinEngine
#endif // LIBJIN_MODULES_RENDER
+
#endif // __JE_CANVAS_H \ No newline at end of file
diff --git a/src/libjin/Graphics/je_color.h b/src/libjin/Graphics/je_color.h
index a3c7582..80c1e4d 100644
--- a/src/libjin/Graphics/je_color.h
+++ b/src/libjin/Graphics/je_color.h
@@ -27,8 +27,14 @@ namespace JinEngine
static const Color MAGENTA;
static const Color YELLOW;
+ ///
+ ///
+ ///
Color() { r = g = b = a = 0; };
-
+
+ ///
+ ///
+ ///
Color(unsigned char _r
, unsigned char _g
, unsigned char _b
diff --git a/src/libjin/Graphics/je_drawable.cpp b/src/libjin/Graphics/je_drawable.cpp
index 00ff739..af9e4d8 100644
--- a/src/libjin/Graphics/je_drawable.cpp
+++ b/src/libjin/Graphics/je_drawable.cpp
@@ -14,42 +14,42 @@ namespace JinEngine
{
Drawable::Drawable(int w, int h)
- : texture(0)
- , size(w, h)
- , anchor(0, 0)
+ : mTexture(0)
+ , mSize(w, h)
+ , mOrigin(0, 0)
{
- vertex_coords[0] = 0; vertex_coords[1] = 0;
- vertex_coords[2] = 0; vertex_coords[3] = h;
- vertex_coords[4] = w; vertex_coords[5] = h;
- vertex_coords[6] = w; vertex_coords[7] = 0;
-
- texture_coords[0] = 0; texture_coords[1] = 0;
- texture_coords[2] = 0; texture_coords[3] = 1;
- texture_coords[4] = 1; texture_coords[5] = 1;
- texture_coords[6] = 1; texture_coords[7] = 0;
+ mVertexCoords[0] = 0; mVertexCoords[1] = 0;
+ mVertexCoords[2] = 0; mVertexCoords[3] = h;
+ mVertexCoords[4] = w; mVertexCoords[5] = h;
+ mVertexCoords[6] = w; mVertexCoords[7] = 0;
+
+ mTextureCoords[0] = 0; mTextureCoords[1] = 0;
+ mTextureCoords[2] = 0; mTextureCoords[3] = 1;
+ mTextureCoords[4] = 1; mTextureCoords[5] = 1;
+ mTextureCoords[6] = 1; mTextureCoords[7] = 0;
}
Drawable::Drawable(const Bitmap* bitmap)
- : texture(0)
- , anchor(0, 0)
+ : mTexture(0)
+ , mOrigin(0, 0)
{
- unsigned int w = size.w = bitmap->getWidth();
- unsigned int h = size.h = bitmap->getHeight();
+ uint32 w = mSize.w = bitmap->getWidth();
+ uint32 h = mSize.h = bitmap->getHeight();
- vertex_coords[0] = 0; vertex_coords[1] = 0;
- vertex_coords[2] = 0; vertex_coords[3] = h;
- vertex_coords[4] = w; vertex_coords[5] = h;
- vertex_coords[6] = w; vertex_coords[7] = 0;
+ mVertexCoords[0] = 0; mVertexCoords[1] = 0;
+ mVertexCoords[2] = 0; mVertexCoords[3] = h;
+ mVertexCoords[4] = w; mVertexCoords[5] = h;
+ mVertexCoords[6] = w; mVertexCoords[7] = 0;
- texture_coords[0] = 0; texture_coords[1] = 0;
- texture_coords[2] = 0; texture_coords[3] = 1;
- texture_coords[4] = 1; texture_coords[5] = 1;
- texture_coords[6] = 1; texture_coords[7] = 0;
+ mTextureCoords[0] = 0; mTextureCoords[1] = 0;
+ mTextureCoords[2] = 0; mTextureCoords[3] = 1;
+ mTextureCoords[4] = 1; mTextureCoords[5] = 1;
+ mTextureCoords[6] = 1; mTextureCoords[7] = 0;
const Color* pixels = bitmap->getPixels();
- texture = gl.genTexture();
- gl.bindTexture(texture);
+ mTexture = gl.genTexture();
+ gl.bindTexture(mTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
@@ -58,26 +58,26 @@ namespace JinEngine
Drawable::~Drawable()
{
- glDeleteTextures(1, &texture);
+ glDeleteTextures(1, &mTexture);
}
- void Drawable::setAnchor(int x, int y)
+ void Drawable::setOrigin(int x, int y)
{
- anchor.x = x;
- anchor.y = y;
+ mOrigin.x = x;
+ mOrigin.y = y;
}
void Drawable::draw(int x, int y, float sx, float sy, float r)
{
- gl.ModelMatrix.setTransformation(x, y, r, sx, sy, anchor.x, anchor.y);
+ gl.ModelMatrix.setTransformation(x, y, r, sx, sy, mOrigin.x, mOrigin.y);
Shader* shader = Shader::getCurrentShader();
shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- shader->bindVertexPointer(2, GL_FLOAT, 0, vertex_coords);
- shader->bindUVPointer(2, GL_FLOAT, 0, texture_coords);
+ shader->bindVertexPointer(2, GL_FLOAT, 0, mVertexCoords);
+ shader->bindUVPointer(2, GL_FLOAT, 0, mTextureCoords);
- gl.bindTexture(texture);
+ gl.bindTexture(mTexture);
gl.drawArrays(GL_QUADS, 0, 4);
gl.bindTexture(0);
}
@@ -90,10 +90,10 @@ namespace JinEngine
slice.w, slice.h,
slice.w, 0
};
- float slx = slice.x / size.w;
- float sly = slice.y / size.h;
- float slw = slice.w / size.w;
- float slh = slice.h / size.h;
+ float slx = slice.x / mSize.w;
+ float sly = slice.y / mSize.h;
+ float slw = slice.w / mSize.w;
+ float slh = slice.h / mSize.h;
float texCoords[8] = {
slx, sly,
slx, sly + slh,
@@ -109,7 +109,7 @@ namespace JinEngine
shader->bindVertexPointer(2, GL_FLOAT, 0, vertCoords);
shader->bindUVPointer(2, GL_FLOAT, 0, texCoords);
- gl.bindTexture(texture);
+ gl.bindTexture(mTexture);
gl.drawArrays(GL_QUADS, 0, 4);
gl.bindTexture(0);
}
diff --git a/src/libjin/Graphics/je_drawable.h b/src/libjin/Graphics/je_drawable.h
index 2547373..1b739cb 100644
--- a/src/libjin/Graphics/je_drawable.h
+++ b/src/libjin/Graphics/je_drawable.h
@@ -37,7 +37,7 @@ namespace JinEngine
///
///
///
- void setAnchor(int x, int y);
+ void setOrigin(int x, int y);
///
///
@@ -52,17 +52,17 @@ namespace JinEngine
///
///
///
- inline int getWidth() const { return size.w; }
+ inline int getWidth() const { return mSize.w; }
///
///
///
- inline int getHeight() const { return size.h; }
+ inline int getHeight() const { return mSize.h; }
///
///
///
- inline GLuint getTexture() const { return texture; }
+ inline GLuint getTexture() const { return mTexture; }
///
///
@@ -72,14 +72,12 @@ namespace JinEngine
protected:
static const int DRAWABLE_V_SIZE = 8;
- GLuint texture;
- GLuint vbo;
- /* TODO: vertex buffer object */
- /* GLuint vbo; */
- JinEngine::Math::Vector2<unsigned int> size;
- JinEngine::Math::Vector2<int> anchor;
- float vertex_coords[DRAWABLE_V_SIZE];
- float texture_coords[DRAWABLE_V_SIZE];
+ GLuint mTexture;
+ GLuint mVBO;
+ JinEngine::Math::Vector2<unsigned int> mSize;
+ JinEngine::Math::Vector2<int> mOrigin;
+ float mVertexCoords[DRAWABLE_V_SIZE];
+ float mTextureCoords[DRAWABLE_V_SIZE];
};
@@ -87,4 +85,5 @@ namespace JinEngine
} // namespace JinEngine
#endif // LIBJIN_MODULES_RENDER
+
#endif // __JE_DRAWABLE \ No newline at end of file
diff --git a/src/libjin/Graphics/je_gl.h b/src/libjin/Graphics/je_gl.h
index 703fdc7..846b90a 100644
--- a/src/libjin/Graphics/je_gl.h
+++ b/src/libjin/Graphics/je_gl.h
@@ -13,9 +13,19 @@ namespace JinEngine
class OpenGL : public ogl2d::OpenGL
{
public:
+ ///
+ ///
+ ///
Math::Matrix ProjectionMatrix;
+
+ ///
+ ///
+ ///
Math::Matrix ModelMatrix;
+ ///
+ ///
+ ///
OpenGL() : ogl2d::OpenGL()
{
}
diff --git a/src/libjin/Graphics/je_image.cpp b/src/libjin/Graphics/je_image.cpp
index a905943..f800423 100644
--- a/src/libjin/Graphics/je_image.cpp
+++ b/src/libjin/Graphics/je_image.cpp
@@ -15,7 +15,7 @@ namespace JinEngine
if (imgData == nullptr)
return nullptr;
int w, h;
- void* data = stbi_load_from_memory((unsigned char *)imgData, size, &w, &h, NULL, STBI_rgb_alpha);
+ void* data = stbi_load_from_memory((uint8*)imgData, size, &w, &h, NULL, STBI_rgb_alpha);
if (data == nullptr)
return nullptr;
Image* image = new Image();
@@ -29,8 +29,8 @@ namespace JinEngine
{
AssetDatabase* fs = AssetDatabase::get();
Buffer buffer;
- fs->read(path, &buffer);
- return createImage(buffer.data, buffer.size);
+ fs->read(path, buffer);
+ return createImage(&buffer, buffer.size());
}
Image::Image()
@@ -43,4 +43,4 @@ namespace JinEngine
}
} // namespace Graphics
-} // namespace JinEngine \ No newline at end of file
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/je_mesh.cpp b/src/libjin/Graphics/je_mesh.cpp
index 4ef5a6e..dd2d61c 100644
--- a/src/libjin/Graphics/je_mesh.cpp
+++ b/src/libjin/Graphics/je_mesh.cpp
@@ -5,7 +5,7 @@ namespace JinEngine
namespace Graphics
{
-
+
} // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/je_mesh.h b/src/libjin/Graphics/je_mesh.h
index 854b701..ed22d91 100644
--- a/src/libjin/Graphics/je_mesh.h
+++ b/src/libjin/Graphics/je_mesh.h
@@ -6,6 +6,9 @@ namespace JinEngine
namespace Graphics
{
+ ///
+ ///
+ ///
class Mesh
{
public:
diff --git a/src/libjin/Graphics/je_shapes.h b/src/libjin/Graphics/je_shapes.h
index ea010be..2221526 100644
--- a/src/libjin/Graphics/je_shapes.h
+++ b/src/libjin/Graphics/je_shapes.h
@@ -1,7 +1,7 @@
#ifndef __JE_GEOMETRY_H
#define __JE_GEOMETRY_H
#include "../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include "je_color.h"
#include "je_canvas.h"
@@ -18,10 +18,6 @@ namespace JinEngine
LINE
}RenderMode;
- /**
- * TODO:
- * drawPixels(int n, points)
- */
extern void line(int x1, int y1, int x2, int y2);
extern void rect(RenderMode mode, int x, int y, int w, int h);
extern void triangle(RenderMode mode, int x1, int y1, int x2, int y2, int x3, int y3);
@@ -33,5 +29,6 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // LIBJIN_MODULES_RENDER
+#endif // jin_graphics
+
#endif // __JE_GEOMETRY_H \ No newline at end of file
diff --git a/src/libjin/Graphics/je_sprite.cpp b/src/libjin/Graphics/je_sprite.cpp
index e69de29..3ac976a 100644
--- a/src/libjin/Graphics/je_sprite.cpp
+++ b/src/libjin/Graphics/je_sprite.cpp
@@ -0,0 +1,11 @@
+#include "je_sprite.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+
+
+ } // namespace Graphics
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h
index 9c3f7a2..23824a7 100644
--- a/src/libjin/Graphics/je_sprite.h
+++ b/src/libjin/Graphics/je_sprite.h
@@ -1,6 +1,10 @@
#ifndef __JE_SPRITE_H
#define __JE_SPRITE_H
+#include "je_color.h"
+#include "../common/je_types.h"
+#include "../math/je_vector2.hpp"
+
namespace JinEngine
{
namespace Graphics
@@ -11,10 +15,16 @@ namespace JinEngine
class Sprite
{
public:
-
+
+ private:
+ Math::Vector2<int> mPosition;
+ Math::Vector2<int> mOrigin;
+ Math::Vector2<int> mScale;
+ Color mColor;
+
};
- }
-}
+ } // namespace Graphics
+} // namespace JinEngine
#endif \ No newline at end of file
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..85a7951
--- /dev/null
+++ b/src/libjin/Graphics/je_sprite_batch.h
@@ -0,0 +1,17 @@
+#ifndef __JE_SPRITE_BATCH_H
+#define __JE_SPRITE_BATCH_H
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+ class SpriteBatch
+ {
+
+ };
+
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/je_window.cpp b/src/libjin/Graphics/je_window.cpp
index bdcb00a..163aa36 100644
--- a/src/libjin/Graphics/je_window.cpp
+++ b/src/libjin/Graphics/je_window.cpp
@@ -70,15 +70,15 @@ namespace JinEngine
return false;
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
SDL_GL_MakeCurrent(wnd, ctx);
- /* default configuration */
+ // default configuration
gl.setClearColor(0, 0, 0, 0xff);
gl.pushColor(0xff, 0xff, 0xff, 0xff);
gl.enable(GL_BLEND);
gl.enable(GL_TEXTURE_2D);
gl.setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- /* avoid white screen blink on windows */
+ // avoid white screen blink on windows
swapBuffers();
- /* bind to default canvas */
+ // bind to default canvas
Canvas::unbind();
Shader::unuse();
return true;
@@ -86,10 +86,10 @@ namespace JinEngine
void Window::quitSystem()
{
- /* disable opengl */
+ // disable opengl
gl.disable(GL_BLEND);
gl.disable(GL_TEXTURE_2D);
- /* close window */
+ // close window
SDL_DestroyWindow(wnd);
SDL_Quit();
}
diff --git a/src/libjin/Graphics/je_window.h b/src/libjin/Graphics/je_window.h
index f7d265f..0969a36 100644
--- a/src/libjin/Graphics/je_window.h
+++ b/src/libjin/Graphics/je_window.h
@@ -59,6 +59,7 @@ namespace JinEngine
void swapBuffers();
private:
+
// declare a singleton
singleton(Window);
diff --git a/src/libjin/Graphics/particle/je_particle.cpp b/src/libjin/Graphics/particle/je_particle.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/particle/je_particle.cpp
diff --git a/src/libjin/Graphics/particle/je_particle.h b/src/libjin/Graphics/particle/je_particle.h
new file mode 100644
index 0000000..ba4dd18
--- /dev/null
+++ b/src/libjin/Graphics/particle/je_particle.h
@@ -0,0 +1,20 @@
+#ifndef __JE_PARTICLE_H
+#define __JE_PARTICLE_H
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+ ///
+ /// Single particle.
+ ///
+ class Particle
+ {
+
+ };
+
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/particle/je_particle_batch.cpp b/src/libjin/Graphics/particle/je_particle_batch.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/particle/je_particle_batch.cpp
diff --git a/src/libjin/Graphics/particle/je_particle_batch.h b/src/libjin/Graphics/particle/je_particle_batch.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/particle/je_particle_batch.h
diff --git a/src/libjin/Graphics/particle/je_particle_emitter.cpp b/src/libjin/Graphics/particle/je_particle_emitter.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/particle/je_particle_emitter.cpp
diff --git a/src/libjin/Graphics/particle/je_particle_emitter.h b/src/libjin/Graphics/particle/je_particle_emitter.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/particle/je_particle_emitter.h
diff --git a/src/libjin/Graphics/particle/je_particle_system.cpp b/src/libjin/Graphics/particle/je_particle_system.cpp
new file mode 100644
index 0000000..6f70f09
--- /dev/null
+++ b/src/libjin/Graphics/particle/je_particle_system.cpp
@@ -0,0 +1 @@
+#pragma once
diff --git a/src/libjin/Graphics/particle/je_particle_system.h b/src/libjin/Graphics/particle/je_particle_system.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/particle/je_particle_system.h