aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-18 20:21:21 +0800
committerchai <chaifix@163.com>2018-09-18 20:21:21 +0800
commitfdf641939870b86e3db9995f0ca5c63d486f80b4 (patch)
tree756d3356ae71db5ebbc5eaf789cfb80010cceeca
parent746290f4fc003311ec43b47584a065e6e8afa3a5 (diff)
*update
-rw-r--r--build/05Font/05Font.vcxproj2
-rw-r--r--build/libjin/libjin.vcxproj7
-rw-r--r--build/libjin/libjin.vcxproj.filters15
-rw-r--r--libjin/Audio/SDL/SDLSource.h2
-rw-r--r--libjin/Filesystem/Filesystem.h2
-rw-r--r--libjin/Graphics/Font.cpp182
-rw-r--r--libjin/Graphics/Font.h89
-rw-r--r--libjin/Graphics/FontData.cpp36
-rw-r--r--libjin/Graphics/FontData.h6
-rw-r--r--libjin/Graphics/Mesh.cpp (renamed from libjin/Graphics/jin_opengl.h)0
-rw-r--r--libjin/Graphics/Mesh.h1
-rw-r--r--libjin/Graphics/OpenGL.cpp11
-rw-r--r--libjin/Graphics/OpenGL.h20
-rw-r--r--libjin/Graphics/Shader.h2
-rw-r--r--test/05Font/main.cpp27
15 files changed, 261 insertions, 141 deletions
diff --git a/build/05Font/05Font.vcxproj b/build/05Font/05Font.vcxproj
index 046472d..5827205 100644
--- a/build/05Font/05Font.vcxproj
+++ b/build/05Font/05Font.vcxproj
@@ -22,7 +22,7 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{D1953718-E728-4A86-9CCF-8BEC1F5C5F97}</ProjectGuid>
<RootNamespace>My05Font</RootNamespace>
- <WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
diff --git a/build/libjin/libjin.vcxproj b/build/libjin/libjin.vcxproj
index 6f3f11b..7e7051c 100644
--- a/build/libjin/libjin.vcxproj
+++ b/build/libjin/libjin.vcxproj
@@ -38,6 +38,8 @@
<ClCompile Include="..\..\libjin\Graphics\Drawable.cpp" />
<ClCompile Include="..\..\libjin\Graphics\Font.cpp" />
<ClCompile Include="..\..\libjin\Graphics\FontData.cpp" />
+ <ClCompile Include="..\..\libjin\Graphics\Mesh.cpp" />
+ <ClCompile Include="..\..\libjin\Graphics\OpenGL.cpp" />
<ClCompile Include="..\..\libjin\Graphics\Shader.cpp" />
<ClCompile Include="..\..\libjin\Graphics\Shapes.cpp" />
<ClCompile Include="..\..\libjin\Graphics\Texture.cpp" />
@@ -88,7 +90,8 @@
<ClInclude Include="..\..\libjin\Graphics\font.shader.h" />
<ClInclude Include="..\..\libjin\Graphics\FontData.h" />
<ClInclude Include="..\..\libjin\Graphics\Graphics.h" />
- <ClInclude Include="..\..\libjin\Graphics\jin_opengl.h" />
+ <ClInclude Include="..\..\libjin\Graphics\Mesh.h" />
+ <ClInclude Include="..\..\libjin\Graphics\OpenGL.h" />
<ClInclude Include="..\..\libjin\Graphics\Shader.h" />
<ClInclude Include="..\..\libjin\Graphics\Shapes.h" />
<ClInclude Include="..\..\libjin\Graphics\Texture.h" />
@@ -123,7 +126,7 @@
<ProjectGuid>{407E9199-D39C-4460-B218-0C29AB42483B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>libjin</RootNamespace>
- <WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
diff --git a/build/libjin/libjin.vcxproj.filters b/build/libjin/libjin.vcxproj.filters
index aa09b0c..8a02ed1 100644
--- a/build/libjin/libjin.vcxproj.filters
+++ b/build/libjin/libjin.vcxproj.filters
@@ -159,6 +159,12 @@
<ClCompile Include="..\..\libjin\Graphics\FontData.cpp">
<Filter>Graphics</Filter>
</ClCompile>
+ <ClCompile Include="..\..\libjin\Graphics\OpenGL.cpp">
+ <Filter>Graphics</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\libjin\Graphics\Mesh.cpp">
+ <Filter>Graphics</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\libjin\3rdparty\GLee\GLee.h">
@@ -306,9 +312,6 @@
<ClInclude Include="..\..\libjin\Graphics\Shapes.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\libjin\Graphics\jin_opengl.h">
- <Filter>Graphics</Filter>
- </ClInclude>
<ClInclude Include="..\..\libjin\jin_configuration.h" />
<ClInclude Include="..\..\libjin\Game\Game.h">
<Filter>Game</Filter>
@@ -337,6 +340,12 @@
<ClInclude Include="..\..\libjin\Graphics\font.shader.h">
<Filter>Graphics</Filter>
</ClInclude>
+ <ClInclude Include="..\..\libjin\Graphics\OpenGL.h">
+ <Filter>Graphics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\libjin\Graphics\Mesh.h">
+ <Filter>Graphics</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\libjin\README.md" />
diff --git a/libjin/Audio/SDL/SDLSource.h b/libjin/Audio/SDL/SDLSource.h
index 40f4693..3feef9f 100644
--- a/libjin/Audio/SDL/SDLSource.h
+++ b/libjin/Audio/SDL/SDLSource.h
@@ -64,7 +64,7 @@ namespace audio
int pitch; // pitch
int state; // ǰ״̬
bool loop; // loop or not
- float volume; //
+ float volume; //
} status;
};
diff --git a/libjin/Filesystem/Filesystem.h b/libjin/Filesystem/Filesystem.h
index ffc0c52..3ae984d 100644
--- a/libjin/Filesystem/Filesystem.h
+++ b/libjin/Filesystem/Filesystem.h
@@ -5,7 +5,7 @@ namespace jin
{
namespace filesystem
{
-
+ /* Դ */
class Filesystem
{
public:
diff --git a/libjin/Graphics/Font.cpp b/libjin/Graphics/Font.cpp
index c8cc56d..f30bc88 100644
--- a/libjin/Graphics/Font.cpp
+++ b/libjin/Graphics/Font.cpp
@@ -17,8 +17,8 @@ namespace graphics
using namespace std;
using namespace jin::math;
- //const int Font::TEXTURE_WIDTHS[] = { 128, 256, 256, 512, 512, 1024, 1024 };
- //const int Font::TEXTURE_HEIGHTS[] = { 128, 128, 256, 256, 512, 512, 1024 };
+ const int Font::TEXTURE_WIDTHS[] = { 128, 256, 256, 512, 512, 1024, 1024 };
+ const int Font::TEXTURE_HEIGHTS[] = { 128, 128, 256, 256, 512, 512, 1024 };
/* utf8 byte string to unicode codepoint */
static const char *utf8toCodepoint(const char *p, unsigned *res) {
@@ -60,17 +60,32 @@ namespace graphics
}
Font::Font(FontData* f, unsigned int fontSize)
- : xoffset(0)
- , yoffset(0)
+ : cursor(0, 0)
, font(f)
, fontsize(fontSize)
{
font->pushFontsize(fontsize);
- baseline = font->getBaseline();
+ font->getVMetrics(&baseline, &descent);
+ estimateSize();
font->popFontsize();
+ /* create a default texture */
createAtlas();
}
+ /* estimate the size of atlas texture */
+ void Font::estimateSize()
+ {
+ for (int level = 0; level <= TEXTURE_SIZE_LEVEL_MAX; ++level)
+ {
+ if (descent * (descent*0.8) * 96 <= TEXTURE_WIDTHS[level] * TEXTURE_HEIGHTS[level])
+ {
+ textureWidth = TEXTURE_WIDTHS[level];
+ textureHeight = TEXTURE_HEIGHTS[level];
+ break;
+ }
+ }
+ }
+
Font::~Font()
{
map<unsigned int, Glyph*>::iterator it = glyphs.begin();
@@ -89,7 +104,7 @@ namespace graphics
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TEXTURE_SIZE, TEXTURE_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
if (glGetError() != GL_NO_ERROR)
{
glDeleteTextures(1, &t);
@@ -101,64 +116,81 @@ namespace graphics
return true;
}
- void Font::print(const char* text, int x, int y)
+ void Font::print(const char* t, int x, int y)
{
- const char* p = text;
- /* xy and uv list */
- vector<GlyphVertex> glyphvertices;
- /* texture binded along with glyphvertices */
+ // typesetting
vector<GlyphArrayDrawInfo> glyphinfolist;
- float dx = 50;
- float dy = 50;
- unsigned int c;
- GLuint texture = 0;
- int start = 0, count = 0;
- do {
- p = utf8toCodepoint(p, &c);
- Glyph* glyph = findGlyph(c);
- if (texture == 0)
- texture = glyph->atlas;
- float xoff = glyph->box.xoff;
- float yoff = glyph->box.yoff;
- float width = glyph->box.width;
- float height = glyph->box.height;
- float mx = glyph->box.width * TEXTURE_SIZE;
- float my = glyph->box.height * TEXTURE_SIZE;
- glyphvertices.push_back(GlyphVertex(dx, dy, xoff, yoff));
- glyphvertices.push_back(GlyphVertex(dx, dy + my, xoff, yoff + height));
- glyphvertices.push_back(GlyphVertex(dx + mx, dy + my, xoff + width, yoff + height));
- glyphvertices.push_back(GlyphVertex(dx + mx, dy, xoff + width, yoff));
- dx += glyph->box.width * TEXTURE_SIZE;
- if (glyph->atlas != texture && texture != 0 || *p == NULL)
+ vector<GlyphVertex> glyphvertices;
+ Vector2<int> p(x, y);
+ Codepoint c;
+ int texture = -1;
+ Glyph* glyph = nullptr;
+ GlyphVertex vertex;
+ for(int i = 0; *t != NULL; i+=4)
+ {
+ t = utf8toCodepoint(t, &c);
+ if (c == 0x0D) continue;
+ /* new line */
+ if (c == 0x0A)
{
- GlyphArrayDrawInfo textureInfo;
- textureInfo.texture = texture;
- textureInfo.startvertex = start;
- textureInfo.vertexcount = (*p == NULL) ? count + 4 : count;
- glyphinfolist.push_back(textureInfo);
- count = 0;
- start = count;
+ p.y += descent;
+ p.x = 0;
+ continue;
}
- count += 4;
- } while (*p != NULL);
+ 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;
+ Glyph::Bbox& bbox = glyph->bbox;
+ // 1
+ vertex.x = p.x; vertex.u = bbox.x;
+ vertex.y = p.y; vertex.v = bbox.y;
+ glyphvertices.push_back(vertex);
+ // 2
+ vertex.x = p.x; vertex.u = bbox.x;
+ vertex.y = p.y + glyph->height; vertex.v = bbox.y + bbox.height;
+ glyphvertices.push_back(vertex);
+ // 3
+ vertex.x = p.x + glyph->width; vertex.u = bbox.x + bbox.width;
+ vertex.y = p.y + glyph->height; vertex.v = bbox.y + bbox.height;
+ glyphvertices.push_back(vertex);
+ // 4
+ vertex.x = p.x + glyph->width; vertex.u = bbox.x + bbox.width;
+ vertex.y = p.y; vertex.v = bbox.y;
+ glyphvertices.push_back(vertex);
+
+ p.x += glyph->width;
+ }
+
+ // draw
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
for (int i = 0; i < glyphinfolist.size(); ++i)
{
GlyphArrayDrawInfo& info = glyphinfolist[i];
glBindTexture(GL_TEXTURE_2D, info.texture);
- int s = sizeof(GlyphVertex);
- glVertexPointer(2, GL_FLOAT, s, &glyphvertices[info.startvertex].x);
- glTexCoordPointer(2, GL_FLOAT, s, &glyphvertices[info.startvertex].u);
- //glDrawArrays(GL_QUADS, 0, info.vertexcount);
+ glVertexPointer(2, GL_INT, sizeof(GlyphVertex), &glyphvertices[info.start].x);
+ glTexCoordPointer(2, GL_FLOAT, sizeof(GlyphVertex), &glyphvertices[info.start].u);
+//#define font_debug
+#if !defined(font_debug)
+ glDrawArrays(GL_QUADS, 0, info.count);
+#endif
glBindTexture(GL_TEXTURE_2D, 0);
}
+#if defined(font_debug)
glBindTexture(GL_TEXTURE_2D, 1);
float xy[] = {
0,0,
- 0,TEXTURE_SIZE,
- TEXTURE_SIZE, TEXTURE_SIZE,
- TEXTURE_SIZE, 0
+ 0,textureHeight,
+ textureWidth, textureHeight,
+ textureWidth, 0
};
float uv[] = {
0, 0,
@@ -170,6 +202,7 @@ namespace graphics
glTexCoordPointer(2, GL_FLOAT, 0, uv);
glDrawArrays(GL_QUADS, 0, 4);
glBindTexture(GL_TEXTURE_2D, 0);
+#endif
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
@@ -200,6 +233,31 @@ namespace graphics
// return ceil(res);
//}
+ int Font::getCharWidth(int c)
+ {
+ return 0;
+ }
+
+ int Font::getCharHeight(int c)
+ {
+ return 0;
+ }
+
+ int Font::getTextWidth(const char* text)
+ {
+ return 0;
+ }
+
+ int Font::getTextHeight(const char* text)
+ {
+ return 0;
+ }
+
+ void Font::getTextBox(const char* text, int* w, int* h)
+ {
+ return ;
+ }
+
Glyph* Font::bakeGlyph(unsigned int character)
{
Glyph* glyph = (Glyph*)malloc(sizeof(Glyph));
@@ -207,18 +265,36 @@ namespace graphics
font->pushFontsize(fontsize);
GLuint atlas = atlases.back();
const Color* bitmap = font->getCodepointBitmap(character, &w, &h, &xoff, &yoff);
+ int adw, lsb;
{
+ font->getHMetrics(character, &adw, &lsb);
font->popFontsize();
+ if (cursor.x + adw > textureWidth )
+ {
+ cursor.x = 0;
+ cursor.y += descent;
+ if (cursor.y + descent > textureHeight)
+ {
+ /* create another atlas */
+ createAtlas();
+ cursor.y = 0;
+ }
+ }
glBindTexture(GL_TEXTURE_2D, atlas);
- glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset + xoff, yoffset + (-yoff), w, h, GL_RGBA, GL_UNSIGNED_BYTE, bitmap);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, cursor.x + xoff, cursor.y + yoff + baseline, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bitmap);
glBindTexture(GL_TEXTURE_2D, 0);
delete[] bitmap;
}
- float s = TEXTURE_SIZE;
glyph->atlas = atlas;
- glyph->box.set(xoffset / s, yoffset / s, (w -xoff)/ s, (h - yoff) / s);
+ glyph->bbox.x = cursor.x / (float)textureWidth;
+ glyph->bbox.y = cursor.y / (float)textureHeight;
+ glyph->bbox.width = adw / (float)textureWidth;
+ glyph->bbox.height = descent / (float)textureHeight;
+ glyph->width = adw;
+ glyph->height = descent;
glyphs.insert(std::pair<unsigned int, Glyph*>(character, glyph));
- xoffset += w;
+
+ cursor.x += adw;
return glyph;
}
diff --git a/libjin/Graphics/Font.h b/libjin/Graphics/Font.h
index c04d64a..a39e6a6 100644
--- a/libjin/Graphics/Font.h
+++ b/libjin/Graphics/Font.h
@@ -16,90 +16,75 @@ namespace graphics
struct GlyphVertex
{
- float x, y;
- float u, v;
- GlyphVertex(float _x, float _y, float _u, float _v)
- {
- set(_x, _y, _u, _v);
- }
- void set(float _x, float _y, float _u, float _v)
- {
- x = _x;
- y = _y;
- u = _u;
- v = _v;
- }
+ int x, y; // screen coordinates
+ float u, v; // texture uv
};
struct GlyphArrayDrawInfo
{
GLuint texture;
- int startvertex;
- int vertexcount;
- };
-
- struct GlyphBox
- {
- float xoff, yoff;
- float width, height;
- void set(float x, float y, float w, float h)
- {
- xoff = x;
- yoff = y;
- width = w;
- height = h;
- }
+ unsigned int start;
+ unsigned int count;
};
struct Glyph
{
- GLuint atlas; // texture where this glyph rendered
- GlyphBox box; // glyph box
+ GLuint atlas;
+ /* normalized coordinates */
+ struct Bbox
+ {
+ float x, y;
+ float width, height;
+ } bbox;
+ /* glyph size in pixel */
+ unsigned int width, height;
};
class Font
{
- private:
- static const int DEFAULT_FONT_SIZE = 12;
-
public:
- static Font* createFont(FontData* fontData, unsigned int fontSzie = DEFAULT_FONT_SIZE);
+ typedef unsigned int Codepoint;
- void print(const char* text, int x, int y);
+ static Font* createFont(FontData* fontData, unsigned int fontSzie);
+ void print(const char* text, int x, int y);
#if defined(font_debug)
void drawAtlas();
#endif
private:
-
/* font atlas levels */
- //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];
- //static const int SPACES_PER_TAB = 4;
- static const int TEXTURE_SIZE = 512;
-
- Font(FontData* font, unsigned int fontSize);
+ 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];
+
+ Font(FontData* font, Codepoint fontSize);
~Font();
+ void estimateSize();
bool createAtlas();
- Glyph* bakeGlyph(unsigned int character);
- Glyph* findGlyph(unsigned int character);
+ Glyph* bakeGlyph(Codepoint character);
+ Glyph* findGlyph(Codepoint character);
- //float getCharWidth(int c, int last);
- //int getTextWidth(const char* text);
+ int getCharWidth(int c);
+ int getCharHeight(int c);
+ int getTextWidth(const char* text);
+ int getTextHeight(const char* text);
+ void getTextBox(const char* text, int* w, int* h);
+ int textureWidth;
+ int textureHeight;
std::vector<GLuint> atlases;
- std::map<unsigned int, Glyph*> glyphs; // map glyph codepoint to Glyph
+ /* map unicode codepoint to glyph */
+ std::map<Codepoint, Glyph*> glyphs;
FontData* font;
const unsigned int fontsize;
- unsigned int baseline;
+ int baseline;
+ int descent;
/* cursor helped render to texture */
- float xoffset;
- float yoffset;
+ math::Vector2<float> cursor;
};
diff --git a/libjin/Graphics/FontData.cpp b/libjin/Graphics/FontData.cpp
index 513b5fa..6a01081 100644
--- a/libjin/Graphics/FontData.cpp
+++ b/libjin/Graphics/FontData.cpp
@@ -41,23 +41,36 @@ namespace graphics
free(raw.data);
}
- int FontData::getBaseline() const
+ /*
+ * (0, 0)
+ * +--------------+ ascent
+ * | +--------+ |
+ * | | | |
+ * | | bitmap | |
+ * +--|--------|--+ baseline
+ * | +--------+ |
+ * +--|-----------+ decent
+ * | |
+ * leftSideBearing|
+ * |
+ * advanceWidth
+ */
+ void FontData::getVMetrics(int* baseline, int* descent)
{
float scale = scales.back();
int ascent;
- stbtt_GetFontVMetrics(&info, &ascent, 0, 0);
- int baseline = (int)(ascent*scale);
- return baseline;
+ stbtt_GetFontVMetrics(&info, &ascent, descent, 0);
+ *baseline = (int)(ascent*scale);
+ *descent = *baseline - (int)(*descent*scale);
}
- unsigned char* FontData::getCodepointBox(unsigned int codepoint, int*x, int* y, int* x1, int*y1)
+ void FontData::getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing)
{
- return 0;
- }
-
- unsigned char* FontData::getCodepointBitmapBox(unsigned int codepoint, int*x, int* y, int* x1, int*y1)
- {
- return 0;
+ float scale = scales.back();
+ int adw, lsb;
+ stbtt_GetCodepointHMetrics(&info, codepoint, &adw, &lsb);
+ *advanceWidth = (int)(adw*scale);
+ *leftSideBearing = (int)(lsb*scale);
}
void FontData::pushFontsize(unsigned int fs)
@@ -85,6 +98,7 @@ namespace graphics
float scale = scales.back();
Channel* bitmap = stbtt_GetCodepointBitmap(&info, scale, scale, codepoint, width, height, xoff, yoff);
int w = *width, h = *height;
+ //int xo = *xoff, yo = *yoff;
Color* bitmap32 = new Color[w*h];
for (int y = 0; y < h; ++y)
{
diff --git a/libjin/Graphics/FontData.h b/libjin/Graphics/FontData.h
index 838f575..c75b9a1 100644
--- a/libjin/Graphics/FontData.h
+++ b/libjin/Graphics/FontData.h
@@ -21,10 +21,8 @@ namespace graphics
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;
- int getBaseline() const;
-
- unsigned char* getCodepointBox(unsigned int codepoint, int*x, int* y, int* x1, int*y1);
- unsigned char* getCodepointBitmapBox(unsigned int codepoint, int*x, int* y, int* x1, int*y1);
+ void getVMetrics(int* baseline, int* descent);
+ void getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing);
private:
static const unsigned int FONT_SIZE = 12;
diff --git a/libjin/Graphics/jin_opengl.h b/libjin/Graphics/Mesh.cpp
index e69de29..e69de29 100644
--- a/libjin/Graphics/jin_opengl.h
+++ b/libjin/Graphics/Mesh.cpp
diff --git a/libjin/Graphics/Mesh.h b/libjin/Graphics/Mesh.h
new file mode 100644
index 0000000..6f70f09
--- /dev/null
+++ b/libjin/Graphics/Mesh.h
@@ -0,0 +1 @@
+#pragma once
diff --git a/libjin/Graphics/OpenGL.cpp b/libjin/Graphics/OpenGL.cpp
new file mode 100644
index 0000000..d89f721
--- /dev/null
+++ b/libjin/Graphics/OpenGL.cpp
@@ -0,0 +1,11 @@
+#include "OpenGL.h"
+
+namespace jin
+{
+namespace graphics
+{
+
+
+
+}
+} \ No newline at end of file
diff --git a/libjin/Graphics/OpenGL.h b/libjin/Graphics/OpenGL.h
new file mode 100644
index 0000000..f73650b
--- /dev/null
+++ b/libjin/Graphics/OpenGL.h
@@ -0,0 +1,20 @@
+#ifndef __LIBJIN_OPENGL_H
+#define __LIBJIN_OPENGL_H
+
+namespace jin
+{
+namespace graphics
+{
+
+ /* 2d wrap of opengl 3.0 */
+ class OpenGL
+ {
+ public:
+ void bindTexture();
+
+ };
+
+}
+}
+
+#endif \ No newline at end of file
diff --git a/libjin/Graphics/Shader.h b/libjin/Graphics/Shader.h
index cf73f3c..bfc787f 100644
--- a/libjin/Graphics/Shader.h
+++ b/libjin/Graphics/Shader.h
@@ -15,7 +15,7 @@ namespace jin
namespace graphics
{
- /* Jin Shader Language Program*/
+ /* Jin Shading Language Program*/
class JSLProgram
{
public:
diff --git a/test/05Font/main.cpp b/test/05Font/main.cpp
index 1b0ae0a..1388537 100644
--- a/test/05Font/main.cpp
+++ b/test/05Font/main.cpp
@@ -1,4 +1,4 @@
-#include <iostream>
+#include <iostream>
#include "jin.h"
using namespace jin::core;
@@ -17,18 +17,19 @@ void onLoad()
uniform float dt;
Color effect(Color col, Texture tex, vec2 uv, vec2 screen)
{
- float d = 150;
- float f = abs((screen.x - d * sin(dt))/20);
- return vec4(col.rgb*(1-f), Texel(tex, uv).a);
+ float d = 130;
+ float f = clamp(abs((screen.x - d * sin(dt))/75), 0, 1);
+ return vec4(col.r*(f), col.g*(1-f + 0.5), 0,Texel(tex, uv).a);
+ //return Texel(tex, uv);
}
)";
shader = JSLProgram::createJSLProgram(program);
Filesystem* fs = Filesystem::get();
fs->mount("../Debug");
Buffer buffer;
- fs->read("SIMYOU.TTF", &buffer);
+ fs->read("font.ttf", &buffer);
data = FontData::createFontData((const unsigned char*)buffer.data, buffer.size);
- font = Font::createFont(data, 14);
+ font = Font::createFont(data, 17);
//canvas = Canvas::createCanvas(100, 100);
}
@@ -49,17 +50,19 @@ void onDraw()
glColor4f(32 / 255.f, 32 / 255.f, 32 / 255.f, 1);
rect(FILL, 0, 0, 500, 500);
glColor4f(1, 1, 1, 1);
- //shader->use();
- //shader->sendFloat("dt", dt);
+ shader->use();
+ shader->sendFloat("dt", dt);
//Canvas::bind(canvas);
if (font != nullptr)
{
glColor4f(1, 1, 1, 1);
- //font->print(u8"ԴZ󤸤Τ", 0, 0);
- font->print(u8"hello, worldԴZ󤸤", 0, 0);
+ font->print(u8"Hello, world!", 10, 10);
+ font->print(u8"Привет мир!", 10, 10 + 15 * 1);
+ font->print(u8"こんにちは世界!", 10, 10 + 15 * 2);
+ font->print(u8"你好世界!", 10, 10 + 15*3);
glColor4f(1, 1, 1, 1);
}
- //shader->unuse();
+ shader->unuse();
//Canvas::unbind();
//canvas->draw(0, 0, 2, 2, 0);
}
@@ -78,7 +81,7 @@ int main(int argc, char* argv[])
Window::Setting wndSetting;
wndSetting.width = 600;
wndSetting.height = 512;
- wndSetting.title = "test";
+ wndSetting.title = "Jin v0.1.1";
wndSetting.fps = 60;
wndSetting.vsync = false;
wndSetting.fullscreen = false;