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_font.h2
-rw-r--r--src/libjin/Graphics/Font/je_page.h2
-rw-r--r--src/libjin/Graphics/Font/je_texture_font.cpp29
-rw-r--r--src/libjin/Graphics/Font/je_ttf.cpp11
-rw-r--r--src/libjin/Graphics/Font/je_ttf.h4
-rw-r--r--src/libjin/Graphics/Shader/je_jsl_compiler.cpp7
-rw-r--r--src/libjin/Graphics/Shader/je_jsl_compiler.h11
-rw-r--r--src/libjin/Graphics/Shader/je_shader.cpp5
-rw-r--r--src/libjin/Graphics/Shader/je_shader.h4
-rw-r--r--src/libjin/Graphics/je_bitmap.cpp11
-rw-r--r--src/libjin/Graphics/je_bitmap.h10
-rw-r--r--src/libjin/Graphics/je_canvas.cpp14
-rw-r--r--src/libjin/Graphics/je_canvas.h4
-rw-r--r--src/libjin/Graphics/je_drawable.cpp4
-rw-r--r--src/libjin/Graphics/je_drawable.h4
-rw-r--r--src/libjin/Graphics/je_gl.h2
-rw-r--r--src/libjin/Graphics/je_graphics.h4
-rw-r--r--src/libjin/Graphics/je_shapes.cpp4
-rw-r--r--src/libjin/Graphics/je_texture.cpp14
-rw-r--r--src/libjin/Graphics/je_texture.h13
-rw-r--r--src/libjin/Graphics/je_window.cpp6
21 files changed, 117 insertions, 48 deletions
diff --git a/src/libjin/Graphics/Font/je_font.h b/src/libjin/Graphics/Font/je_font.h
index 75dd4c5..4529902 100644
--- a/src/libjin/Graphics/Font/je_font.h
+++ b/src/libjin/Graphics/Font/je_font.h
@@ -97,4 +97,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif \ No newline at end of file
+#endif // __JE_FONT_H \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_page.h b/src/libjin/Graphics/Font/je_page.h
index 7df2784..fbc297e 100644
--- a/src/libjin/Graphics/Font/je_page.h
+++ b/src/libjin/Graphics/Font/je_page.h
@@ -48,4 +48,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif \ No newline at end of file
+#endif // __JE_PAGE_H \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_texture_font.cpp b/src/libjin/Graphics/Font/je_texture_font.cpp
index 81ac343..f85a8ce 100644
--- a/src/libjin/Graphics/Font/je_texture_font.cpp
+++ b/src/libjin/Graphics/Font/je_texture_font.cpp
@@ -72,19 +72,27 @@ namespace JinEngine
for (Codepoint c : text)
{
+ // return
if (c == 0x0D) continue;
+ // newline
if (c == 0x0A)
{
- /* new line */
p.y += lineheight;
p.x = 0;
continue;
}
+ if (c == 0x09)
+ {
+ // tab = 4*space
+ unsigned cw = getCharWidth(0x20);
+ p.x += cw * 4;
+ continue;
+ }
glyph = findGlyph(c);
if (glyph == nullptr) continue;
- if (texture != this->texture)
+ if (texture != mTexture)
{
- texture = this->texture;
+ texture = mTexture;
GlyphArrayDrawInfo info;
info.start = i;
info.count = 0;
@@ -93,8 +101,8 @@ namespace JinEngine
}
glyphinfolist[glyphinfolist.size() - 1].count += 4;
// normalized
- float nx = glyph->x / (float)size.w, ny = glyph->y / (float)size.h;
- float nw = glyph->w / (float)size.w, nh = glyph->h / (float)size.h;
+ float nx = glyph->x / (float)mSize.w, ny = glyph->y / (float)mSize.h;
+ float nw = glyph->w / (float)mSize.w, nh = glyph->h / (float)mSize.h;
glyphvertices_push(p.x, p.y, nx, ny);
glyphvertices_push(p.x, p.y + glyph->h, nx, ny + nh);
glyphvertices_push(p.x + glyph->w, p.y + glyph->h, nx + nw, ny + nh);
@@ -139,9 +147,16 @@ namespace JinEngine
tmp = 0;
continue;
}
+ if (c == 0x09)
+ {
+ // tab = 4*space
+ unsigned cw = getCharWidth(0x20);
+ tmp += cw * 4;
+ if (tmp > res) res = tmp;
+ continue;
+ }
tmp += getCharWidth(c) + spacing;
- if (tmp > res)
- res = tmp;
+ if (tmp > res) res = tmp;
}
return res;
}
diff --git a/src/libjin/Graphics/Font/je_ttf.cpp b/src/libjin/Graphics/Font/je_ttf.cpp
index 0ee02ab..a11efb0 100644
--- a/src/libjin/Graphics/Font/je_ttf.cpp
+++ b/src/libjin/Graphics/Font/je_ttf.cpp
@@ -1,5 +1,5 @@
#include "../../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include <stdio.h>
@@ -279,6 +279,13 @@ namespace JinEngine
p.x = 0;
continue;
}
+ if (c == 0x09)
+ {
+ // tab = 4*space
+ unsigned cw = getCharWidth(0x20);
+ p.x += cw * 4;
+ continue;
+ }
glyphlize(c);
p.x += glyph->width + spacing;
i += 4;
@@ -453,4 +460,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
+#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_ttf.h b/src/libjin/Graphics/Font/je_ttf.h
index 9acb07e..7bc6934 100644
--- a/src/libjin/Graphics/Font/je_ttf.h
+++ b/src/libjin/Graphics/Font/je_ttf.h
@@ -1,7 +1,7 @@
#ifndef __JETTF_H
#define __JE_TTF_H
#include "../../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include <vector>
#include <map>
@@ -283,6 +283,6 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // LIBJIN_MODULES_RENDER
+#endif // defined(jin_graphics)
#endif // __JE_FONT_H \ No newline at end of file
diff --git a/src/libjin/Graphics/Shader/je_jsl_compiler.cpp b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp
index 490caea..2683969 100644
--- a/src/libjin/Graphics/Shader/je_jsl_compiler.cpp
+++ b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp
@@ -1,3 +1,6 @@
+#include "../../core/je_configuration.h"
+#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
+
#include "je_jsl_compiler.h"
namespace JinEngine
@@ -8,4 +11,6 @@ namespace JinEngine
} // namespace Graphics
-} // namespace JinEngine \ No newline at end of file
+} // namespace JinEngine
+
+#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) \ 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
index b530466..1817a7b 100644
--- a/src/libjin/Graphics/Shader/je_jsl_compiler.h
+++ b/src/libjin/Graphics/Shader/je_jsl_compiler.h
@@ -1,6 +1,9 @@
#ifndef __JE_JSL_COMPILER_H
#define __JE_JSL_COMPILER_H
+#include "../../core/je_configuration.h"
+#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
+
#include "../../common/je_singleton.hpp"
namespace JinEngine
@@ -21,7 +24,9 @@ namespace JinEngine
};
- }
-}
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader)
-#endif \ No newline at end of file
+#endif // __JE_JSL_COMPILER_H \ 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 6066864..6c8076a 100644
--- a/src/libjin/Graphics/Shader/je_shader.cpp
+++ b/src/libjin/Graphics/Shader/je_shader.cpp
@@ -1,6 +1,5 @@
-#include <regex>
#include "../../core/je_configuration.h"
-#if defined(jin_graphics_shader)
+#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
#include <iostream>
@@ -285,4 +284,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // jin_graphics_shader \ No newline at end of file
+#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) \ No newline at end of file
diff --git a/src/libjin/Graphics/Shader/je_shader.h b/src/libjin/Graphics/Shader/je_shader.h
index 69746de..928fb0a 100644
--- a/src/libjin/Graphics/Shader/je_shader.h
+++ b/src/libjin/Graphics/Shader/je_shader.h
@@ -2,7 +2,7 @@
#define __JE_SHADER_H
#include "../../core/je_configuration.h"
-#if defined(jin_graphics) && defined(jin_graphics_shader)
+#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
#include <string>
#include <map>
@@ -195,6 +195,6 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // jin_graphics && jin_graphics_shader
+#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader)
#endif // __JE_SHADER_H \ No newline at end of file
diff --git a/src/libjin/Graphics/je_bitmap.cpp b/src/libjin/Graphics/je_bitmap.cpp
index 5269606..0747f0b 100644
--- a/src/libjin/Graphics/je_bitmap.cpp
+++ b/src/libjin/Graphics/je_bitmap.cpp
@@ -1,9 +1,12 @@
#define STB_IMAGE_IMPLEMENTATION
#include "../3rdparty/stb/stb_image.h"
+
+#include "../filesystem/je_asset_database.h"
#include "../math/je_math.h"
#include "je_bitmap.h"
+using namespace JinEngine::Filesystem;
using namespace JinEngine::Math;
namespace JinEngine
@@ -11,6 +14,14 @@ namespace JinEngine
namespace Graphics
{
+ Bitmap* Bitmap::createBitmap(const char* path)
+ {
+ AssetDatabase* ad = AssetDatabase::get();
+ Buffer buffer;
+ ad->read(path, buffer);
+ return createBitmap(&buffer, buffer.size());
+ }
+
/* pixelbitmap */
Bitmap* Bitmap::createBitmap(const void* pixel, unsigned width, unsigned height)
{
diff --git a/src/libjin/Graphics/je_bitmap.h b/src/libjin/Graphics/je_bitmap.h
index d9d0981..445bf91 100644
--- a/src/libjin/Graphics/je_bitmap.h
+++ b/src/libjin/Graphics/je_bitmap.h
@@ -1,7 +1,7 @@
#ifndef __JE_BITMAP_H
#define __JE_BITMAP_H
#include "../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include "../3rdparty/GLee/GLee.h"
#include "../common/je_types.h"
@@ -22,6 +22,14 @@ namespace JinEngine
class Bitmap
{
public:
+ ///
+ /// Create bitmap from given file.
+ ///
+ /// @param path Path of image file.
+ /// @return Bitmap if create successful, otherwise retrun false.
+ ///
+ static Bitmap* createBitmap(const char* path);
+
///
/// Create bitmap by pixels data.
///
diff --git a/src/libjin/Graphics/je_canvas.cpp b/src/libjin/Graphics/je_canvas.cpp
index b8553b5..6406e5f 100644
--- a/src/libjin/Graphics/je_canvas.cpp
+++ b/src/libjin/Graphics/je_canvas.cpp
@@ -1,5 +1,5 @@
#include "../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include "../utils/je_macros.h"
#include "je_canvas.h"
@@ -34,13 +34,13 @@ namespace JinEngine
gl.bindFrameBuffer(fbo);
// generate texture save target
- texture = gl.genTexture();
- gl.bindTexture(texture);
+ mTexture = gl.genTexture();
+ gl.bindTexture(mTexture);
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);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
@@ -65,8 +65,8 @@ namespace JinEngine
if (isBinded(canvas)) return;
current = canvas;
gl.bindFrameBuffer(canvas->fbo);
- int w = canvas->size.w;
- int h = canvas->size.h;
+ int w = canvas->mSize.w;
+ int h = canvas->mSize.h;
/* set view port to canvas */
glViewport(0, 0, w, h);
gl.ProjectionMatrix.setOrtho(0, w, 0, h, -1, 1);
@@ -99,4 +99,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
+#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 9839899..a4c0330 100644
--- a/src/libjin/Graphics/je_canvas.h
+++ b/src/libjin/Graphics/je_canvas.h
@@ -1,7 +1,7 @@
#ifndef __JE_CANVAS_H
#define __JE_CANVAS_H
#include "../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include "je_drawable.h"
@@ -63,6 +63,6 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // LIBJIN_MODULES_RENDER
+#endif // defined(jin_graphics)
#endif // __JE_CANVAS_H \ No newline at end of file
diff --git a/src/libjin/Graphics/je_drawable.cpp b/src/libjin/Graphics/je_drawable.cpp
index af9e4d8..7480a32 100644
--- a/src/libjin/Graphics/je_drawable.cpp
+++ b/src/libjin/Graphics/je_drawable.cpp
@@ -1,5 +1,5 @@
#include "../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include <stdlib.h>
@@ -122,4 +122,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
+#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/Graphics/je_drawable.h b/src/libjin/Graphics/je_drawable.h
index 1b739cb..fdf9ea2 100644
--- a/src/libjin/Graphics/je_drawable.h
+++ b/src/libjin/Graphics/je_drawable.h
@@ -1,7 +1,7 @@
#ifndef __JE_DRAWABLE
#define __JE_DRAWABLE
#include "../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include "../math/je_quad.h"
#include "../math/je_vector2.hpp"
@@ -84,6 +84,6 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // LIBJIN_MODULES_RENDER
+#endif // defined(jin_graphics)
#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 846b90a..cda8bf9 100644
--- a/src/libjin/Graphics/je_gl.h
+++ b/src/libjin/Graphics/je_gl.h
@@ -37,4 +37,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif \ No newline at end of file
+#endif // __JE_OPENGL_H \ No newline at end of file
diff --git a/src/libjin/Graphics/je_graphics.h b/src/libjin/Graphics/je_graphics.h
index 8c964c3..2ba003d 100644
--- a/src/libjin/Graphics/je_graphics.h
+++ b/src/libjin/Graphics/je_graphics.h
@@ -1,7 +1,7 @@
#ifndef __JE_GRAPHICS_H
#define __JE_GRAPHICS_H
#include "../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include "je_canvas.h"
#include "je_color.h"
@@ -17,5 +17,5 @@
#include "font/je_text.h"
#include "font/je_texture_font.h"
-#endif // LIBJIN_MODULES_RENDER
+#endif // defined(jin_graphics)
#endif // __JE_GRAPHICS_H \ No newline at end of file
diff --git a/src/libjin/Graphics/je_shapes.cpp b/src/libjin/Graphics/je_shapes.cpp
index 5a6dee8..3146f31 100644
--- a/src/libjin/Graphics/je_shapes.cpp
+++ b/src/libjin/Graphics/je_shapes.cpp
@@ -1,5 +1,5 @@
#include "../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include <string>
@@ -125,4 +125,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
+#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/Graphics/je_texture.cpp b/src/libjin/Graphics/je_texture.cpp
index da56047..d191c8b 100644
--- a/src/libjin/Graphics/je_texture.cpp
+++ b/src/libjin/Graphics/je_texture.cpp
@@ -1,5 +1,5 @@
#include "../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include <fstream>
@@ -8,12 +8,20 @@
#include "je_texture.h"
+using namespace JinEngine::Math;
+
namespace JinEngine
{
namespace Graphics
{
- using namespace JinEngine::Math;
+ Texture* Texture::createTexture(const char* path)
+ {
+ Bitmap* bitmap = Bitmap::createBitmap(path);
+ Texture* texture = createTexture(bitmap);
+ delete bitmap;
+ return texture;
+ }
/*static*/ Texture* Texture::createTexture(Bitmap* bitmap)
{
@@ -33,4 +41,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
+#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 e5c9cff..5238aa1 100644
--- a/src/libjin/Graphics/je_texture.h
+++ b/src/libjin/Graphics/je_texture.h
@@ -13,6 +13,7 @@ namespace JinEngine
{
namespace Graphics
{
+
///
///
///
@@ -22,7 +23,17 @@ namespace JinEngine
///
///
///
- static Texture* createTexture(Bitmap* bitmap);
+ static Texture* createTexture(const char* path);
+
+ ///
+ ///
+ ///
+ static Texture* createTexture(Bitmap* bitmap);
+
+ ///
+ ///
+ ///
+ static Texture* createTexture();
///
///
diff --git a/src/libjin/Graphics/je_window.cpp b/src/libjin/Graphics/je_window.cpp
index 163aa36..8c36c85 100644
--- a/src/libjin/Graphics/je_window.cpp
+++ b/src/libjin/Graphics/je_window.cpp
@@ -1,5 +1,5 @@
#include "../core/je_configuration.h"
-#if LIBJIN_MODULES_RENDER
+#if defined(jin_graphics)
#include <iostream>
@@ -19,7 +19,7 @@ namespace JinEngine
bool Window::initSystem(const SettingBase* s)
{
- #if LIBJIN_DEBUG
+ #if defined(jin_debug)
Loghelper::log(Loglevel::LV_INFO, "Init window system");
#endif
@@ -108,4 +108,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
+#endif // defined(jin_graphics) \ No newline at end of file