aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics')
-rw-r--r--src/libjin/graphics/fonts/je_decoder.cpp6
-rw-r--r--src/libjin/graphics/fonts/je_decoder.h6
-rw-r--r--src/libjin/graphics/fonts/je_font.h6
-rw-r--r--src/libjin/graphics/fonts/je_page.h6
-rw-r--r--src/libjin/graphics/fonts/je_text.cpp6
-rw-r--r--src/libjin/graphics/fonts/je_text.h6
-rw-r--r--src/libjin/graphics/fonts/je_texture_font.cpp12
-rw-r--r--src/libjin/graphics/fonts/je_texture_font.h6
-rw-r--r--src/libjin/graphics/fonts/je_ttf.cpp48
-rw-r--r--src/libjin/graphics/fonts/je_ttf.h6
-rw-r--r--src/libjin/graphics/je_bitmap.cpp200
-rw-r--r--src/libjin/graphics/je_bitmap.h44
-rw-r--r--src/libjin/graphics/je_canvas.cpp56
-rw-r--r--src/libjin/graphics/je_canvas.h22
-rw-r--r--src/libjin/graphics/je_color.cpp20
-rw-r--r--src/libjin/graphics/je_color.h116
-rw-r--r--src/libjin/graphics/je_gl.cpp8
-rw-r--r--src/libjin/graphics/je_gl.h16
-rw-r--r--src/libjin/graphics/je_graphic.h40
-rw-r--r--src/libjin/graphics/je_image.cpp16
-rw-r--r--src/libjin/graphics/je_image.h26
-rw-r--r--src/libjin/graphics/je_mesh.cpp6
-rw-r--r--src/libjin/graphics/je_mesh.h16
-rw-r--r--src/libjin/graphics/je_shapes.cpp188
-rw-r--r--src/libjin/graphics/je_shapes.h30
-rw-r--r--src/libjin/graphics/je_sprite.h4
-rw-r--r--src/libjin/graphics/je_texture.cpp30
-rw-r--r--src/libjin/graphics/je_texture.h18
-rw-r--r--src/libjin/graphics/je_window.cpp154
-rw-r--r--src/libjin/graphics/je_window.h56
-rw-r--r--src/libjin/graphics/shaders/je_base.shader.h19
-rw-r--r--src/libjin/graphics/shaders/je_shader.cpp10
-rw-r--r--src/libjin/graphics/shaders/je_shader.h6
33 files changed, 604 insertions, 605 deletions
diff --git a/src/libjin/graphics/fonts/je_decoder.cpp b/src/libjin/graphics/fonts/je_decoder.cpp
index 02112a0..a7f4f32 100644
--- a/src/libjin/graphics/fonts/je_decoder.cpp
+++ b/src/libjin/graphics/fonts/je_decoder.cpp
@@ -4,8 +4,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -92,5 +92,5 @@ namespace JinEngine
}
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_decoder.h b/src/libjin/graphics/fonts/je_decoder.h
index 0c785af..43fa155 100644
--- a/src/libjin/graphics/fonts/je_decoder.h
+++ b/src/libjin/graphics/fonts/je_decoder.h
@@ -9,8 +9,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -93,7 +93,7 @@ namespace JinEngine
};
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_font.h b/src/libjin/graphics/fonts/je_font.h
index e8ce2c5..3af0b11 100644
--- a/src/libjin/graphics/fonts/je_font.h
+++ b/src/libjin/graphics/fonts/je_font.h
@@ -9,8 +9,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -106,7 +106,7 @@ namespace JinEngine
};
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // __JE_FONT_H__
diff --git a/src/libjin/graphics/fonts/je_page.h b/src/libjin/graphics/fonts/je_page.h
index b3c831c..d831691 100644
--- a/src/libjin/graphics/fonts/je_page.h
+++ b/src/libjin/graphics/fonts/je_page.h
@@ -7,8 +7,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -48,7 +48,7 @@ namespace JinEngine
};
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // __JE_PAGE_H__
diff --git a/src/libjin/graphics/fonts/je_text.cpp b/src/libjin/graphics/fonts/je_text.cpp
index 80aaa6a..f9909a6 100644
--- a/src/libjin/graphics/fonts/je_text.cpp
+++ b/src/libjin/graphics/fonts/je_text.cpp
@@ -5,8 +5,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -153,5 +153,5 @@ namespace JinEngine
}
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_text.h b/src/libjin/graphics/fonts/je_text.h
index 319ee4d..6837bfc 100644
--- a/src/libjin/graphics/fonts/je_text.h
+++ b/src/libjin/graphics/fonts/je_text.h
@@ -7,8 +7,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -168,7 +168,7 @@ namespace JinEngine
};
}
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_texture_font.cpp b/src/libjin/graphics/fonts/je_texture_font.cpp
index 9014509..4f2378b 100644
--- a/src/libjin/graphics/fonts/je_texture_font.cpp
+++ b/src/libjin/graphics/fonts/je_texture_font.cpp
@@ -12,8 +12,8 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -124,9 +124,9 @@ namespace JinEngine
int i = 0;
#define glyphvertices_push(_x, _y, _u, _v) \
- vertex.x = _x; vertex.y = _y;\
- vertex.u = _u; vertex.v = _v;\
- glyphvertices.push_back(vertex);\
+ vertex.x = _x; vertex.y = _y;\
+ vertex.u = _u; vertex.v = _v;\
+ glyphvertices.push_back(vertex);\
for (Codepoint c : text)
{
@@ -304,5 +304,5 @@ namespace JinEngine
}
}
- }
+ }
} \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_texture_font.h b/src/libjin/graphics/fonts/je_texture_font.h
index 4875361..9192276 100644
--- a/src/libjin/graphics/fonts/je_texture_font.h
+++ b/src/libjin/graphics/fonts/je_texture_font.h
@@ -15,8 +15,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -125,7 +125,7 @@ namespace JinEngine
};
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_ttf.cpp b/src/libjin/graphics/fonts/je_ttf.cpp
index fec8cd4..40008d3 100644
--- a/src/libjin/graphics/fonts/je_ttf.cpp
+++ b/src/libjin/graphics/fonts/je_ttf.cpp
@@ -19,8 +19,8 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -234,29 +234,29 @@ namespace JinEngine
int i = 0;
#define glyphvertices_push(_x, _y, _u, _v) \
- vertex.x = _x; vertex.y = _y;\
- vertex.u = _u; vertex.v = _v;\
- glyphvertices.push_back(vertex);
+ vertex.x = _x; vertex.y = _y;\
+ vertex.u = _u; vertex.v = _v;\
+ glyphvertices.push_back(vertex);
#define glyphlize(c)\
- do{\
- glyph = &findGlyph(c); \
- if (texture != glyph->atlas) \
- { \
- GlyphArrayDrawInfo info; \
- info.start = i; \
- info.count = 0; \
- info.texture = glyph->atlas; \
- texture = glyph->atlas; \
- glyphinfolist.push_back(info); \
- } \
- glyphinfolist[glyphinfolist.size() - 1].count += 4; \
- TTFGlyph::Bbox& bbox = glyph->bbox; \
- glyphvertices_push(p.x, p.y, bbox.x, bbox.y); \
- glyphvertices_push(p.x, p.y + glyph->height, bbox.x, bbox.y + bbox.h); \
- glyphvertices_push(p.x + glyph->width, p.y + glyph->height, bbox.x + bbox.w, bbox.y + bbox.h); \
- glyphvertices_push(p.x + glyph->width, p.y, bbox.x + bbox.w, bbox.y); \
- }while(0)
+ do{\
+ glyph = &findGlyph(c); \
+ if (texture != glyph->atlas) \
+ { \
+ GlyphArrayDrawInfo info; \
+ info.start = i; \
+ info.count = 0; \
+ info.texture = glyph->atlas; \
+ texture = glyph->atlas; \
+ glyphinfolist.push_back(info); \
+ } \
+ glyphinfolist[glyphinfolist.size() - 1].count += 4; \
+ TTFGlyph::Bbox& bbox = glyph->bbox; \
+ glyphvertices_push(p.x, p.y, bbox.x, bbox.y); \
+ glyphvertices_push(p.x, p.y + glyph->height, bbox.x, bbox.y + bbox.h); \
+ glyphvertices_push(p.x + glyph->width, p.y + glyph->height, bbox.x + bbox.w, bbox.y + bbox.h); \
+ glyphvertices_push(p.x + glyph->width, p.y, bbox.x + bbox.w, bbox.y); \
+ }while(0)
for (Codepoint c : text)
{
@@ -448,7 +448,7 @@ namespace JinEngine
}
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_ttf.h b/src/libjin/graphics/fonts/je_ttf.h
index 198594a..feabf33 100644
--- a/src/libjin/graphics/fonts/je_ttf.h
+++ b/src/libjin/graphics/fonts/je_ttf.h
@@ -19,8 +19,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -278,7 +278,7 @@ namespace JinEngine
};
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics)
diff --git a/src/libjin/graphics/je_bitmap.cpp b/src/libjin/graphics/je_bitmap.cpp
index 18e15a8..eadd6d1 100644
--- a/src/libjin/graphics/je_bitmap.cpp
+++ b/src/libjin/graphics/je_bitmap.cpp
@@ -12,30 +12,30 @@ using namespace JinEngine::Math;
namespace JinEngine
{
- namespace Graphics
- {
-
- Bitmap* Bitmap::clone()
- {
- Bitmap* b = new Bitmap(this);
- return b;
- }
-
- Bitmap::Bitmap()
- : width(0)
- , height(0)
- , pixels(nullptr)
- {
- }
-
- Bitmap::Bitmap(unsigned w, unsigned h)
- {
- width = w;
- height = h;
- pixels = new Color[w*h];
+ namespace Graphics
+ {
+
+ Bitmap* Bitmap::clone()
+ {
+ Bitmap* b = new Bitmap(this);
+ return b;
+ }
+
+ Bitmap::Bitmap()
+ : width(0)
+ , height(0)
+ , pixels(nullptr)
+ {
+ }
+
+ Bitmap::Bitmap(unsigned w, unsigned h)
+ {
+ width = w;
+ height = h;
+ pixels = new Color[w*h];
if (pixels == nullptr)
throw Exception("No enough memory.");
- }
+ }
Bitmap::Bitmap(const char* path)
{
@@ -96,94 +96,94 @@ namespace JinEngine
resetPixels(bitmap->getPixels(), w, h);
}
- Bitmap::~Bitmap()
- {
- stbi_image_free(pixels);
- }
-
- void Bitmap::bind(Color* p, int w, int h)
- {
- if (pixels != nullptr)
- delete[] pixels;
- pixels = p;
- width = w;
- height = h;
- }
-
- void Bitmap::resetPixels(const Color* p, int w, int h)
- {
- if (pixels != nullptr)
- delete[] pixels;
- pixels = new Color[w*h];
+ Bitmap::~Bitmap()
+ {
+ stbi_image_free(pixels);
+ }
+
+ void Bitmap::bind(Color* p, int w, int h)
+ {
+ if (pixels != nullptr)
+ delete[] pixels;
+ pixels = p;
+ width = w;
+ height = h;
+ }
+
+ void Bitmap::resetPixels(const Color* p, int w, int h)
+ {
+ if (pixels != nullptr)
+ delete[] pixels;
+ pixels = new Color[w*h];
if (pixels == nullptr)
throw Exception("Not enough memory.");
- size_t s = w * h * sizeof(Color);
- memcpy(pixels, p, s);
- width = w;
- height = h;
- }
-
- void Bitmap::setPixel(const Color& c, int x, int y)
- {
+ size_t s = w * h * sizeof(Color);
+ memcpy(pixels, p, s);
+ width = w;
+ height = h;
+ }
+
+ void Bitmap::setPixel(const Color& c, int x, int y)
+ {
if (pixels == nullptr)
throw Exception("Bitmap don't have pixel space.");
- if (without<int>(x, 0, width - 1) || without<int>(y, 0, height - 1))
- return;
+ if (without<int>(x, 0, width - 1) || without<int>(y, 0, height - 1))
+ return;
if (x + y * width >= width * height)
throw Exception("Pixel <%d, %d> of bitmap is out of range.", x, y);
- pixels[x + y * width] = c;
- }
-
- void Bitmap::resetPixels(const Color& c, int w, int h)
- {
- if (pixels != nullptr)
- delete[] pixels;
- pixels = new Color[w*h];
+ pixels[x + y * width] = c;
+ }
+
+ void Bitmap::resetPixels(const Color& c, int w, int h)
+ {
+ if (pixels != nullptr)
+ delete[] pixels;
+ pixels = new Color[w*h];
if (pixels == nullptr)
throw Exception("Not enough memory.");
- width = w;
- height = h;
- for (int x = 0; x < w; ++x)
- {
- for (int y = 0; y < h; ++y)
- {
- pixels[x + y * w] = c;
- }
- }
- }
-
- void Bitmap::setPixels(Color* p, int count)
- {
+ width = w;
+ height = h;
+ for (int x = 0; x < w; ++x)
+ {
+ for (int y = 0; y < h; ++y)
+ {
+ pixels[x + y * w] = c;
+ }
+ }
+ }
+
+ void Bitmap::setPixels(Color* p, int count)
+ {
if (count > width * height)
throw Exception("Pixels are out of range.");
- size_t s = width * height * sizeof(Color);
- memcpy(pixels, p, s);
- }
-
- void Bitmap::setPixels(Color c)
- {
- for (int x = 0; x < width; ++x)
- {
- for (int y = 0; y < height; ++y)
- {
- pixels[x + y * width] = c;
- }
- }
- }
-
- Color Bitmap::getPixel(int x, int y)
- {
- if (pixels == nullptr)
- return Color::BLACK;
- if (without<int>(x, 0, width - 1) || without<int>(y, 0, height - 1))
- return Color::BLACK;
- return pixels[x + y * width];
- }
+ size_t s = width * height * sizeof(Color);
+ memcpy(pixels, p, s);
+ }
+
+ void Bitmap::setPixels(Color c)
+ {
+ for (int x = 0; x < width; ++x)
+ {
+ for (int y = 0; y < height; ++y)
+ {
+ pixels[x + y * width] = c;
+ }
+ }
+ }
+
+ Color Bitmap::getPixel(int x, int y)
+ {
+ if (pixels == nullptr)
+ return Color::BLACK;
+ if (without<int>(x, 0, width - 1) || without<int>(y, 0, height - 1))
+ return Color::BLACK;
+ return pixels[x + y * width];
+ }
- const Color* Bitmap::getPixels() const
- {
- return pixels;
- }
+ const Color* Bitmap::getPixels() const
+ {
+ return pixels;
+ }
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/je_bitmap.h b/src/libjin/graphics/je_bitmap.h
index c392a32..644e56e 100644
--- a/src/libjin/graphics/je_bitmap.h
+++ b/src/libjin/graphics/je_bitmap.h
@@ -14,8 +14,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
///
/// A RGBA32 bitmap.
@@ -24,9 +24,9 @@ namespace JinEngine
/// texture is a renderable hard ware side structure which could be handled with GPU. For instance, opengl
/// create texture and store it in GPU memory for rendering them onto hdc.
///
- class Bitmap : public Object
- {
- public:
+ class Bitmap : public Object
+ {
+ public:
///
/// Constructor of bitmap.
///
@@ -55,7 +55,7 @@ namespace JinEngine
///
/// Destructor of bitmap
///
- virtual ~Bitmap();
+ virtual ~Bitmap();
///
/// Create bitmap with another one.
@@ -72,7 +72,7 @@ namespace JinEngine
/// @param width Width of bitmap
/// @param height Height of bitmap
///
- void bind(Color* pixels, int width, int height);
+ void bind(Color* pixels, int width, int height);
///
/// Reset pixel data with given pixels data.
@@ -81,7 +81,7 @@ namespace JinEngine
/// @param width Width of bitmap
/// @param height Height of bitmap
///
- void resetPixels(const Color* pixels, int width, int height);
+ void resetPixels(const Color* pixels, int width, int height);
///
/// Reset pixel data with given color.
@@ -90,7 +90,7 @@ namespace JinEngine
/// @param width Width of bitmap
/// @param height Height of bitmap
///
- void resetPixels(const Color& color, int width, int height);
+ void resetPixels(const Color& color, int width, int height);
///
/// Set pixel with given color.
@@ -99,14 +99,14 @@ namespace JinEngine
/// @param x X value of pixel.
/// @param y Y value of pixel.
///
- void setPixel(const Color& color, int x, int y);
+ void setPixel(const Color& color, int x, int y);
///
/// Set pixels with given color.
///
/// @param color Color to be set.
///
- void setPixels(Color color);
+ void setPixels(Color color);
///
/// Set pixels with given color data.
@@ -114,7 +114,7 @@ namespace JinEngine
/// @param colors New pixels' colors.
/// @param count Number of pixels.
///
- void setPixels(Color* colors, int count);
+ void setPixels(Color* colors, int count);
///
/// Get pixel in given position.
@@ -122,42 +122,42 @@ namespace JinEngine
/// @param x X value of position.
/// @param y Y value of position.
///
- Color getPixel(int x, int y);
+ Color getPixel(int x, int y);
///
/// Get pixels.
/// @return Colors of the bitmap.
///
- const Color* getPixels() const;
+ const Color* getPixels() const;
///
/// Get bitmap width.
///
/// @return Width of bitmap.
///
- inline int getWidth() const { return width; }
+ inline int getWidth() const { return width; }
///
/// Get bitmap height.
///
/// @return Height of bitmap.
///
- inline int getHeight() const { return height; }
+ inline int getHeight() const { return height; }
///
/// Get bitmap size.
///
/// @return Size of bitmap.
///
- inline Math::Vector2<int> getSize() const { return Math::Vector2<int>(width, height); }
+ inline Math::Vector2<int> getSize() const { return Math::Vector2<int>(width, height); }
- protected:
- Color * pixels;
- unsigned width, height;
+ protected:
+ Color * pixels;
+ unsigned width, height;
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif
diff --git a/src/libjin/graphics/je_canvas.cpp b/src/libjin/graphics/je_canvas.cpp
index 564121e..0a3f6f4 100644
--- a/src/libjin/graphics/je_canvas.cpp
+++ b/src/libjin/graphics/je_canvas.cpp
@@ -7,48 +7,48 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
Canvas::Canvas(GLuint n)
: fbo(n)
{
}
- Canvas::Canvas(int w, int h)
- : Graphic(w, h)
- {
- GLint current_fbo;
- glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
+ Canvas::Canvas(int w, int h)
+ : Graphic(w, h)
+ {
+ GLint current_fbo;
+ glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
- // Generate a new render buffer object
- fbo = gl.genFrameBuffer();
- gl.bindFrameBuffer(fbo);
+ // Generate a new render buffer object
+ fbo = gl.genFrameBuffer();
+ gl.bindFrameBuffer(fbo);
GLuint texture = getGLTexture();
- gl.bindTexture(texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- gl.bindTexture(0);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
+ gl.bindTexture(texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ gl.bindTexture(0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
- GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- // Unbind framebuffer
- gl.bindFrameBuffer(current_fbo);
- }
+ // Unbind framebuffer
+ gl.bindFrameBuffer(current_fbo);
+ }
- Canvas::~Canvas()
- {
- }
+ Canvas::~Canvas()
+ {
+ }
- bool Canvas::isBinded(const Canvas* cvs)
- {
- return gl.getCanvas() == cvs;
- }
+ bool Canvas::isBinded(const Canvas* cvs)
+ {
+ return gl.getCanvas() == cvs;
+ }
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/graphics/je_canvas.h b/src/libjin/graphics/je_canvas.h
index 277e39d..b65e598 100644
--- a/src/libjin/graphics/je_canvas.h
+++ b/src/libjin/graphics/je_canvas.h
@@ -7,20 +7,20 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
///
/// Renderable canvas.
///
/// A canvas is a rendering target.
///
- class Canvas : public Graphic
- {
- public:
+ class Canvas : public Graphic
+ {
+ public:
///
///
///
- static bool isBinded(const Canvas*);
+ static bool isBinded(const Canvas*);
///
///
@@ -35,17 +35,17 @@ namespace JinEngine
///
///
///
- ~Canvas();
+ ~Canvas();
inline GLuint getGLFrameBuffer() const { return fbo; };
- protected:
+ protected:
- GLuint fbo;
+ GLuint fbo;
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics)
diff --git a/src/libjin/graphics/je_color.cpp b/src/libjin/graphics/je_color.cpp
index c939a1d..ea936fa 100644
--- a/src/libjin/graphics/je_color.cpp
+++ b/src/libjin/graphics/je_color.cpp
@@ -2,21 +2,21 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- const Color Color::WHITE = Color(255, 255, 255);
- const Color Color::BLACK = Color(0, 0, 0);
- const Color Color::RED = Color(255, 0, 0);
- const Color Color::GREEN = Color(0, 255, 0);
- const Color Color::BLUE = Color(0, 0, 255);
- const Color Color::MAGENTA = Color(255, 0, 255);
- const Color Color::YELLOW = Color(255, 255, 0);
+ const Color Color::WHITE = Color(255, 255, 255);
+ const Color Color::BLACK = Color(0, 0, 0);
+ const Color Color::RED = Color(255, 0, 0);
+ const Color Color::GREEN = Color(0, 255, 0);
+ const Color Color::BLUE = Color(0, 0, 255);
+ const Color Color::MAGENTA = Color(255, 0, 255);
+ const Color Color::YELLOW = Color(255, 255, 0);
const uint32 Color::RMASK = 0x000000ff;
const uint32 Color::GMASK = 0x0000ff00;
const uint32 Color::BMASK = 0x00ff0000;
const uint32 Color::AMASK = 0xff000000;
- }
+ }
} \ No newline at end of file
diff --git a/src/libjin/graphics/je_color.h b/src/libjin/graphics/je_color.h
index 06b8f61..96120e3 100644
--- a/src/libjin/graphics/je_color.h
+++ b/src/libjin/graphics/je_color.h
@@ -13,22 +13,22 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- typedef uint8 Channel;
+ typedef uint8 Channel;
- class Color
- {
- public:
+ class Color
+ {
+ public:
// Built-in colors
static const Color WHITE;
- static const Color BLACK;
- static const Color RED;
- static const Color GREEN;
- static const Color BLUE;
- static const Color MAGENTA;
- static const Color YELLOW;
+ static const Color BLACK;
+ static const Color RED;
+ static const Color GREEN;
+ static const Color BLUE;
+ static const Color MAGENTA;
+ static const Color YELLOW;
static const uint32 RMASK;
static const uint32 GMASK;
@@ -57,61 +57,61 @@ namespace JinEngine
///
///
///
- Color() { r = g = b = a = 0; };
+ Color() { r = g = b = a = 0; };
///
///
///
- Color(unsigned char _r
- , unsigned char _g
- , unsigned char _b
- , unsigned char _a = 255)
- {
- r = _r;
- g = _g;
- b = _b;
- a = _a;
- }
+ Color(unsigned char _r
+ , unsigned char _g
+ , unsigned char _b
+ , unsigned char _a = 255)
+ {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _a;
+ }
- Color(const Color& c)
- {
- r = c.r;
- g = c.g;
- b = c.b;
- a = c.a;
- }
-
- void set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a)
- {
- r = _r;
- g = _g;
- b = _b;
- a = _a;
- }
-
- void operator = (const Color& c)
- {
- r = c.r;
- g = c.g;
- b = c.b;
- a = c.a;
- }
-
- bool operator == (const Color& c)
- {
- return r == c.r && g == c.g && b == c.b && a == c.a;
- }
+ Color(const Color& c)
+ {
+ r = c.r;
+ g = c.g;
+ b = c.b;
+ a = c.a;
+ }
+
+ void set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a)
+ {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _a;
+ }
+
+ void operator = (const Color& c)
+ {
+ r = c.r;
+ g = c.g;
+ b = c.b;
+ a = c.a;
+ }
+
+ bool operator == (const Color& c)
+ {
+ return r == c.r && g == c.g && b == c.b && a == c.a;
+ }
- bool operator != (const Color& c)
- {
- return !(r == c.r && g == c.g && b == c.b && a == c.a);
- }
+ bool operator != (const Color& c)
+ {
+ return !(r == c.r && g == c.g && b == c.b && a == c.a);
+ }
- Channel r, g, b, a;
+ Channel r, g, b, a;
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // jin_graphics
diff --git a/src/libjin/graphics/je_gl.cpp b/src/libjin/graphics/je_gl.cpp
index 453b4b4..41fdf76 100644
--- a/src/libjin/graphics/je_gl.cpp
+++ b/src/libjin/graphics/je_gl.cpp
@@ -13,10 +13,10 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- OpenGL gl;
+ OpenGL gl;
const Canvas* const OpenGL::DEFAULT_CANVAS = new Canvas(0);
@@ -359,5 +359,5 @@ namespace JinEngine
return mFont;
}
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/je_gl.h b/src/libjin/graphics/je_gl.h
index de381f4..37dc890 100644
--- a/src/libjin/graphics/je_gl.h
+++ b/src/libjin/graphics/je_gl.h
@@ -12,8 +12,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
// Wrap OpenGL API.
namespace Shaders { class Shader; };
@@ -23,9 +23,9 @@ namespace JinEngine
class Canvas;
- class OpenGL
- {
- public:
+ class OpenGL
+ {
+ public:
///
/// Blend mode.
/// https://www.andersriggelsen.dk/glblendfunc.php
@@ -229,12 +229,12 @@ namespace JinEngine
///
Fonts::Font* mFont;
- };
+ };
// Singleton.
- extern OpenGL gl;
+ extern OpenGL gl;
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // __JE_OPENGL_H__ \ No newline at end of file
diff --git a/src/libjin/graphics/je_graphic.h b/src/libjin/graphics/je_graphic.h
index 90b5522..f47adbf 100644
--- a/src/libjin/graphics/je_graphic.h
+++ b/src/libjin/graphics/je_graphic.h
@@ -17,43 +17,43 @@ namespace JinEngine
namespace Graphics
{
- ///
- /// Class inherites Graphic doesn't keep any state such as origin, scale and other properties. Very low
+ ///
+ /// Class inherites Graphic doesn't keep any state such as origin, scale and other properties. Very low
/// level visualized resources.
///
class Graphic : public Object, public Renderable
{
public:
- ///
- ///
- ///
+ ///
+ ///
+ ///
Graphic(int w = 0, int h = 0);
- ///
- ///
- ///
+ ///
+ ///
+ ///
Graphic(const Bitmap* bitmap);
- ///
- ///
- ///
+ ///
+ ///
+ ///
virtual ~Graphic();
- ///
- ///
- ///
+ ///
+ ///
+ ///
inline int getWidth() const { return mSize.w; }
- ///
- ///
- ///
+ ///
+ ///
+ ///
inline int getHeight() const { return mSize.h; }
- ///
- /// Get opengl texture token.
+ ///
+ /// Get opengl texture token.
///
/// @return OpenGL texture token.
- ///
+ ///
inline GLuint getGLTexture() const { return mTexture; }
///
diff --git a/src/libjin/graphics/je_image.cpp b/src/libjin/graphics/je_image.cpp
index 285cef2..46ae34f 100644
--- a/src/libjin/graphics/je_image.cpp
+++ b/src/libjin/graphics/je_image.cpp
@@ -33,14 +33,14 @@ namespace JinEngine
height = h;
}
- Image::Image()
- : Bitmap()
- {
- }
-
- Image::~Image()
- {
- }
+ Image::Image()
+ : Bitmap()
+ {
+ }
+
+ Image::~Image()
+ {
+ }
} // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/je_image.h b/src/libjin/graphics/je_image.h
index 432b875..f23e8c6 100644
--- a/src/libjin/graphics/je_image.h
+++ b/src/libjin/graphics/je_image.h
@@ -13,9 +13,9 @@ namespace JinEngine
///
/// Just like bitmap but only from image file. The pixels data is readonly.
///
- class Image : public Bitmap
- {
- public:
+ class Image : public Bitmap
+ {
+ public:
///
/// Image constructor.
///
@@ -28,18 +28,18 @@ namespace JinEngine
///
/// Image destructor.
///
- ~Image();
+ ~Image();
- private:
+ private:
// Disable setters inherited from Bitmap.
- void bind(Color* pixels, int w, int h);
- void resetPixels(const Color* pixels, int w, int h);
- void resetPixels(const Color& pixels, int w, int h);
- void setPixel(const Color& pixel, int x, int y);
- void setPixels(Color pixels);
- void setPixels(Color* pixels);
-
- };
+ void bind(Color* pixels, int w, int h);
+ void resetPixels(const Color* pixels, int w, int h);
+ void resetPixels(const Color& pixels, int w, int h);
+ void setPixel(const Color& pixel, int x, int y);
+ void setPixels(Color pixels);
+ void setPixels(Color* pixels);
+
+ };
} // namespace Graphics
} // namespace JinEngine
diff --git a/src/libjin/graphics/je_mesh.cpp b/src/libjin/graphics/je_mesh.cpp
index dd2d61c..a88abbd 100644
--- a/src/libjin/graphics/je_mesh.cpp
+++ b/src/libjin/graphics/je_mesh.cpp
@@ -2,10 +2,10 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- } // 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 4327424..5bcca2e 100644
--- a/src/libjin/graphics/je_mesh.h
+++ b/src/libjin/graphics/je_mesh.h
@@ -5,24 +5,24 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
///
/// A 2D mesh.
///
- class Mesh
- {
- public:
+ class Mesh
+ {
+ public:
void setGraphic(const Graphic* graphic);
void pushVertex(float x, float y, float u, float v);
- private:
+ private:
const Graphic* mGraphic;
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/graphics/je_shapes.cpp b/src/libjin/graphics/je_shapes.cpp
index ee5e9e5..02c007d 100644
--- a/src/libjin/graphics/je_shapes.cpp
+++ b/src/libjin/graphics/je_shapes.cpp
@@ -13,118 +13,118 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- using namespace Math;
+ using namespace Math;
- void point(int x, int y)
- {
- float verts[] = { x + 0.5f , y + 0.5f };
+ void point(int x, int y)
+ {
+ float verts[] = { x + 0.5f , y + 0.5f };
- Shader* shader = gl.getShader();
- shader->setVertexPointer(2, GL_FLOAT, 0, verts);
+ Shader* shader = gl.getShader();
+ shader->setVertexPointer(2, GL_FLOAT, 0, verts);
Matrix modelMatrix = gl.getModelViewMatrix();
- shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+ shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
- glDrawArrays(GL_POINTS, 0, 1);
- }
+ glDrawArrays(GL_POINTS, 0, 1);
+ }
- void points(int n, GLshort* p)
- {
- Shader* shader = gl.getShader();
- shader->setVertexPointer(2, GL_SHORT, 0, p);
+ void points(int n, GLshort* p)
+ {
+ Shader* shader = gl.getShader();
+ shader->setVertexPointer(2, GL_SHORT, 0, p);
Matrix modelMatrix = gl.getModelViewMatrix();
shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+
+ glDrawArrays(GL_POINTS, 0, n);
+ }
+
+ void line(int x1, int y1, int x2, int y2)
+ {
+ float verts[] = {
+ x1 + 0.5f, y1 + 0.5f,
+ x2 + 0.5f, y2 + 0.5f
+ };
- glDrawArrays(GL_POINTS, 0, n);
- }
-
- void line(int x1, int y1, int x2, int y2)
- {
- float verts[] = {
- x1 + 0.5f, y1 + 0.5f,
- x2 + 0.5f, y2 + 0.5f
- };
-
- Shader* shader = gl.getShader();
- shader->setVertexPointer(2, GL_FLOAT, 0, verts);
+ Shader* shader = gl.getShader();
+ shader->setVertexPointer(2, GL_FLOAT, 0, verts);
Matrix modelMatrix = gl.getModelViewMatrix();
shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
- glDrawArrays(GL_LINES, 0, 2);
- }
-
- void circle(RenderMode mode, int x, int y, int r)
- {
- r = r < 0 ? 0 : r;
-
- int points = 40;
- float two_pi = static_cast<float>(PI * 2);
- if (points <= 0) points = 1;
- float angle_shift = (two_pi / points);
- float phi = .0f;
-
- float *coords = new float[2 * (points + 1)];
- for (int i = 0; i < points; ++i, phi += angle_shift)
- {
- coords[2 * i] = x + r * cos(phi);
- coords[2 * i + 1] = y + r * sin(phi);
- }
-
- coords[2 * points] = coords[0];
- coords[2 * points + 1] = coords[1];
-
- polygon(mode, coords, points);
-
- delete[] coords;
- }
-
- void rect(RenderMode mode, int x, int y, int w, int h)
- {
- float coords[] = { x + 0.5f, y + 0.5f, x + w + 0.5f, y + 0.5f, x + w + 0.5f, y + h + 0.5f, x + 0.5f, y + h + 0.5f };
- polygon(mode, coords, 4);
- }
-
- void triangle(RenderMode mode, int x1, int y1, int x2, int y2, int x3, int y3)
- {
- float coords[] = { x1 + 0.5f, y1 + 0.5f, x2 + 0.5f, y2 + 0.5f, x3 + 0.5f, y3 + 0.5f };
- polygon(mode, coords, 3);
- }
-
- void polygon_line(float* p, int count)
- {
- Shader* shader = gl.getShader();
+ glDrawArrays(GL_LINES, 0, 2);
+ }
+
+ void circle(RenderMode mode, int x, int y, int r)
+ {
+ r = r < 0 ? 0 : r;
+
+ int points = 40;
+ float two_pi = static_cast<float>(PI * 2);
+ if (points <= 0) points = 1;
+ float angle_shift = (two_pi / points);
+ float phi = .0f;
+
+ float *coords = new float[2 * (points + 1)];
+ for (int i = 0; i < points; ++i, phi += angle_shift)
+ {
+ coords[2 * i] = x + r * cos(phi);
+ coords[2 * i + 1] = y + r * sin(phi);
+ }
+
+ coords[2 * points] = coords[0];
+ coords[2 * points + 1] = coords[1];
+
+ polygon(mode, coords, points);
+
+ delete[] coords;
+ }
+
+ void rect(RenderMode mode, int x, int y, int w, int h)
+ {
+ float coords[] = { x + 0.5f, y + 0.5f, x + w + 0.5f, y + 0.5f, x + w + 0.5f, y + h + 0.5f, x + 0.5f, y + h + 0.5f };
+ polygon(mode, coords, 4);
+ }
+
+ void triangle(RenderMode mode, int x1, int y1, int x2, int y2, int x3, int y3)
+ {
+ float coords[] = { x1 + 0.5f, y1 + 0.5f, x2 + 0.5f, y2 + 0.5f, x3 + 0.5f, y3 + 0.5f };
+ polygon(mode, coords, 3);
+ }
+
+ void polygon_line(float* p, int count)
+ {
+ Shader* shader = gl.getShader();
Matrix modelMatrix = gl.getModelViewMatrix();
shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
- shader->setVertexPointer(2, GL_FLOAT, 0, p);
-
- glDrawArrays(GL_LINE_LOOP, 0, count);
- }
-
- void polygon(RenderMode mode, float* p, int count)
- {
- if (mode == LINE)
- {
- polygon_line(p, count);
- }
- else if (mode == FILL)
- {
- Shader* shader = gl.getShader();
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+ shader->setVertexPointer(2, GL_FLOAT, 0, p);
+
+ glDrawArrays(GL_LINE_LOOP, 0, count);
+ }
+
+ void polygon(RenderMode mode, float* p, int count)
+ {
+ if (mode == LINE)
+ {
+ polygon_line(p, count);
+ }
+ else if (mode == FILL)
+ {
+ Shader* shader = gl.getShader();
Matrix modelMatrix = gl.getModelViewMatrix();
shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
- shader->setVertexPointer(2, GL_FLOAT, 0, p);
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+ shader->setVertexPointer(2, GL_FLOAT, 0, p);
- glDrawArrays(GL_POLYGON, 0, count);
- }
- }
+ glDrawArrays(GL_POLYGON, 0, count);
+ }
+ }
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/graphics/je_shapes.h b/src/libjin/graphics/je_shapes.h
index d62592b..dcc134d 100644
--- a/src/libjin/graphics/je_shapes.h
+++ b/src/libjin/graphics/je_shapes.h
@@ -9,24 +9,24 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- enum RenderMode {
- NONE = 0,
- FILL ,
- LINE
- };
+ enum RenderMode {
+ NONE = 0,
+ FILL ,
+ LINE
+ };
- 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);
- extern void circle(RenderMode mode, int x, int y, int r);
- extern void point(int x, int y);
- extern void points(int n, GLshort* p, GLubyte* c);
- extern void polygon(RenderMode mode, float* p, int count);
+ 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);
+ extern void circle(RenderMode mode, int x, int y, int r);
+ extern void point(int x, int y);
+ extern void points(int n, GLshort* p, GLubyte* c);
+ extern void polygon(RenderMode mode, float* p, int count);
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // jin_graphics
diff --git a/src/libjin/graphics/je_sprite.h b/src/libjin/graphics/je_sprite.h
index 70e8f7b..fe38a4a 100644
--- a/src/libjin/graphics/je_sprite.h
+++ b/src/libjin/graphics/je_sprite.h
@@ -17,7 +17,7 @@ namespace JinEngine
/// A sprite is unit of rendering. Animation is based on sprite, but not texture or other graphic stuff.
///
class Sprite : public Object, public Renderable
- {
+ {
public:
Sprite(const Graphic* graphic, const Math::Quad& quad, Origin origin);
@@ -47,7 +47,7 @@ namespace JinEngine
const Graphic* mGraphic;
- };
+ };
} // namespace Graphics
} // namespace JinEngine
diff --git a/src/libjin/graphics/je_texture.cpp b/src/libjin/graphics/je_texture.cpp
index 8d9bb0a..152e5d0 100644
--- a/src/libjin/graphics/je_texture.cpp
+++ b/src/libjin/graphics/je_texture.cpp
@@ -12,8 +12,8 @@ using namespace JinEngine::Math;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
/*
Texture* Texture::createTexture(const char* path)
{
@@ -23,11 +23,11 @@ namespace JinEngine
return texture;
}
- Texture* Texture::createTexture(Bitmap* bitmap)
- {
- Texture* tex = new Texture(bitmap);
- return tex;
- }
+ Texture* Texture::createTexture(Bitmap* bitmap)
+ {
+ Texture* tex = new Texture(bitmap);
+ return tex;
+ }
*/
Texture::Texture()
: Graphic()
@@ -41,16 +41,16 @@ namespace JinEngine
delete bitmap;
}
- Texture::Texture(const Bitmap* bitmap)
- : Graphic(bitmap)
- {
- }
+ Texture::Texture(const Bitmap* bitmap)
+ : Graphic(bitmap)
+ {
+ }
- Texture::~Texture()
- {
- }
+ Texture::~Texture()
+ {
+ }
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/graphics/je_texture.h b/src/libjin/graphics/je_texture.h
index 94e7a01..6e14111 100644
--- a/src/libjin/graphics/je_texture.h
+++ b/src/libjin/graphics/je_texture.h
@@ -11,20 +11,20 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
///
///
///
- class Texture : public Graphic
- {
- public:
+ class Texture : public Graphic
+ {
+ public:
/*
///
///
///
- static Texture* createTexture(const char* path);
+ static Texture* createTexture(const char* path);
///
///
@@ -55,11 +55,11 @@ namespace JinEngine
///
///
///
- ~Texture();
+ ~Texture();
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // jin_graphics
diff --git a/src/libjin/graphics/je_window.cpp b/src/libjin/graphics/je_window.cpp
index 6572304..3260e14 100644
--- a/src/libjin/graphics/je_window.cpp
+++ b/src/libjin/graphics/je_window.cpp
@@ -17,57 +17,57 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
-
- bool Window::startSystem(const SettingBase* s)
- {
- jin_log_info("Initialize window system.");
-
- if (SDL_Init(SDL_INIT_VIDEO) < 0)
- return false;
-
- const Setting* setting = (Setting*)s;
- mSize.w = setting->width;
+ namespace Graphics
+ {
+
+ bool Window::startSystem(const SettingBase* s)
+ {
+ jin_log_info("Initialize window system.");
+
+ if (SDL_Init(SDL_INIT_VIDEO) < 0)
+ return false;
+
+ const Setting* setting = (Setting*)s;
+ mSize.w = setting->width;
mSize.h = setting->height;
- mFps = setting->fps;
- bool vsync = setting->vsync;
- const char* title = setting->title;
+ mFps = setting->fps;
+ bool vsync = setting->vsync;
+ const char* title = setting->title;
const char* icon = setting->icon;
- if (mWnd)
- {
- SDL_DestroyWindow(mWnd);
- SDL_FlushEvent(SDL_WINDOWEVENT);
- }
-
- SDL_GLContext ctx = NULL;
-
- if (ctx)
- {
- SDL_GL_DeleteContext(ctx);
- }
-
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ if (mWnd)
+ {
+ SDL_DestroyWindow(mWnd);
+ SDL_FlushEvent(SDL_WINDOWEVENT);
+ }
+
+ SDL_GLContext ctx = NULL;
+
+ if (ctx)
+ {
+ SDL_GL_DeleteContext(ctx);
+ }
+
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
- int wx = SDL_WINDOWPOS_UNDEFINED,
- wy = SDL_WINDOWPOS_UNDEFINED;
+ int wx = SDL_WINDOWPOS_UNDEFINED,
+ wy = SDL_WINDOWPOS_UNDEFINED;
- int flag = SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
- if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
- if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
+ int flag = SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
+ if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
+ if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
mWnd = SDL_CreateWindow(title, wx, wy, mSize.w, mSize.h, flag);
- if (mWnd == NULL)
- return false;
+ if (mWnd == NULL)
+ return false;
// Set window icon.
try
@@ -82,49 +82,49 @@ namespace JinEngine
SDL_FreeSurface(surface);
} catch (...) {}
- ctx = SDL_GL_CreateContext(mWnd);
- if (ctx == NULL)
- return false;
- SDL_GL_SetSwapInterval(vsync ? 1 : 0);
- SDL_GL_MakeCurrent(mWnd, ctx);
- // Default configuration.
- gl.setClearColor(0, 0, 0, 0xff);
+ ctx = SDL_GL_CreateContext(mWnd);
+ if (ctx == NULL)
+ return false;
+ SDL_GL_SetSwapInterval(vsync ? 1 : 0);
+ SDL_GL_MakeCurrent(mWnd, ctx);
+ // Default configuration.
+ gl.setClearColor(0, 0, 0, 0xff);
glClear(GL_COLOR_BUFFER_BIT);
gl.setColor(0xff, 0xff, 0xff, 0xff);
- gl.enable(GL_BLEND);
- gl.enable(GL_TEXTURE_2D);
+ gl.enable(GL_BLEND);
+ gl.enable(GL_TEXTURE_2D);
// Default blend function.
gl.setBlendMode(OpenGL::BlendMode::ALPHA);
- // Bind to default canvas.
+ // Bind to default canvas.
gl.unbindCanvas();
gl.unuseShader();
- return true;
- }
+ return true;
+ }
- void Window::quitSystem()
- {
+ void Window::quitSystem()
+ {
jin_log_info("Quit window system.");
- // disable opengl
- gl.disable(GL_BLEND);
- gl.disable(GL_TEXTURE_2D);
- // close window
- SDL_DestroyWindow(mWnd);
- SDL_Quit();
- }
-
- void Window::swapBuffers()
- {
- if (mWnd)
- SDL_GL_SwapWindow(mWnd);
- }
-
- void Window::setTitle(const char* title)
- {
- SDL_SetWindowTitle(mWnd, title);
- };
-
- } // namespace Graphics
+ // disable opengl
+ gl.disable(GL_BLEND);
+ gl.disable(GL_TEXTURE_2D);
+ // close window
+ SDL_DestroyWindow(mWnd);
+ SDL_Quit();
+ }
+
+ void Window::swapBuffers()
+ {
+ if (mWnd)
+ SDL_GL_SwapWindow(mWnd);
+ }
+
+ void Window::setTitle(const char* title)
+ {
+ SDL_SetWindowTitle(mWnd, title);
+ };
+
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/graphics/je_window.h b/src/libjin/graphics/je_window.h
index 6e23445..902e873 100644
--- a/src/libjin/graphics/je_window.h
+++ b/src/libjin/graphics/je_window.h
@@ -11,29 +11,29 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
///
///
///
- class Window
+ class Window
: public Subsystem<Window>
- {
- public:
+ {
+ public:
///
///
///
- struct Setting : SettingBase
- {
- public:
- const char* title; ///< window title
+ struct Setting : SettingBase
+ {
+ public:
+ const char* title; ///< window title
const char* icon; ///< window icon
- bool fullscreen; ///< full screen
- int width, height; ///< window size
- bool vsync; ///< vsync
- int fps; ///< frame per second
- bool resizable; ///< resizable
- };
+ bool fullscreen; ///< full screen
+ int width, height; ///< window size
+ bool vsync; ///< vsync
+ int fps; ///< frame per second
+ bool resizable; ///< resizable
+ };
///
///
@@ -48,27 +48,27 @@ namespace JinEngine
///
///
///
- void setTitle(const char* title);
+ void setTitle(const char* title);
///
///
///
- inline int getW(){ return mSize.w; }
+ inline int getW(){ return mSize.w; }
///
///
///
- inline int getH(){ return mSize.h; }
+ inline int getH(){ return mSize.h; }
///
///
///
- inline int getFPS(){ return mFps; }
+ inline int getFPS(){ return mFps; }
///
///
///
- void swapBuffers();
+ void swapBuffers();
///
///
@@ -80,25 +80,25 @@ namespace JinEngine
///
void show() { SDL_ShowWindow(mWnd); };
- private:
+ private:
///
///
///
- bool startSystem(const SettingBase* setting) override;
+ bool startSystem(const SettingBase* setting) override;
///
///
///
- void quitSystem() override;
+ void quitSystem() override;
- SDL_Window* mWnd;
- JinEngine::Math::Vector2<unsigned int> mSize;
- int mFps;
+ SDL_Window* mWnd;
+ JinEngine::Math::Vector2<unsigned int> mSize;
+ int mFps;
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // jin_graphics
diff --git a/src/libjin/graphics/shaders/je_base.shader.h b/src/libjin/graphics/shaders/je_base.shader.h
index 34996bc..1cecddf 100644
--- a/src/libjin/graphics/shaders/je_base.shader.h
+++ b/src/libjin/graphics/shaders/je_base.shader.h
@@ -2,13 +2,13 @@
#define __JE_BASE_SHADER_H__
static const char* base_shared = R"(
-#define Number float
+#define Number float
#define Texture sampler2D
#define Canvas sampler2D
#define Color vec4
-#define Vec2 vec2
-#define Vec3 vec3
-#define Vec4 vec4
+#define Vec2 vec2
+#define Vec3 vec3
+#define Vec4 vec4
#define texel texture2D
@@ -26,9 +26,8 @@ static const char* base_vertex = R"(
#version 130 core
%s
-// Projection matrix
+
uniform mat4 jin_ProjectionMatrix;
-// Model view matrix
uniform mat4 jin_ModelViewMatrix;
in vec2 jin_VertexCoords;
@@ -42,10 +41,10 @@ out vec2 jin_UV;
void main()
{
- vec4 v = jin_ModelViewMatrix * vec4(jin_VertexCoords, 0, 1.0);
+ vec4 v = jin_ModelViewMatrix * vec4(jin_VertexCoords, 0, 1.0);
Vertex _v = vert(Vertex(v.xy, jin_TextureCoords));
- gl_Position = jin_ProjectionMatrix * vec4(_v.xy, 0, 1.0f);
- jin_Color = gl_Color;
+ gl_Position = jin_ProjectionMatrix * vec4(_v.xy, 0, 1.0f);
+ jin_Color = gl_Color;
jin_XY = _v.xy;
jin_UV = _v.uv;
}
@@ -86,4 +85,4 @@ static const char* SHADER_MAIN_TEXTURE = "jin_MainTexture";
static const char* SHADER_VERTEX_COORDS = "jin_VertexCoords";
static const char* SHADER_TEXTURE_COORDS = "jin_TextureCoords";
-#endif // __JE_BASE_SHADER_H__
+#endif // __JE_BASE_SHADER_H__ \ No newline at end of file
diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp
index 017231a..b7a4bba 100644
--- a/src/libjin/graphics/shaders/je_shader.cpp
+++ b/src/libjin/graphics/shaders/je_shader.cpp
@@ -16,8 +16,8 @@ using namespace JinEngine::Filesystem;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Shaders
{
@@ -145,8 +145,8 @@ if (success == GL_FALSE) \
}
#define checkJSL() \
- if (gl.getShader() != this) \
- return
+ if (gl.getShader() != this) \
+ return
void Shader::sendInt(const char* name, int value)
{
@@ -267,7 +267,7 @@ if (success == GL_FALSE) \
}
} // namespace Shaders
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) \ No newline at end of file
diff --git a/src/libjin/graphics/shaders/je_shader.h b/src/libjin/graphics/shaders/je_shader.h
index d8be118..2ccc537 100644
--- a/src/libjin/graphics/shaders/je_shader.h
+++ b/src/libjin/graphics/shaders/je_shader.h
@@ -17,8 +17,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Shaders
{
@@ -175,7 +175,7 @@ namespace JinEngine
};
} // namespace Shaders
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader)