diff options
| -rw-r--r-- | build/05Font/05Font.vcxproj | 2 | ||||
| -rw-r--r-- | build/libjin/libjin.vcxproj | 2 | ||||
| -rw-r--r-- | libjin/Graphics/Font.cpp | 50 | ||||
| -rw-r--r-- | libjin/Graphics/Font.h | 8 | ||||
| -rw-r--r-- | libjin/Graphics/Mesh.cpp | 11 | ||||
| -rw-r--r-- | libjin/Graphics/Mesh.h | 18 | ||||
| -rw-r--r-- | libjin/Graphics/OpenGL.h | 15 | ||||
| -rw-r--r-- | test/05Font/main.cpp | 18 | 
8 files changed, 92 insertions, 32 deletions
diff --git a/build/05Font/05Font.vcxproj b/build/05Font/05Font.vcxproj index 5827205..046472d 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>8.1</WindowsTargetPlatformVersion> +    <WindowsTargetPlatformVersion>10.0.14393.0</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 7e7051c..9dac72a 100644 --- a/build/libjin/libjin.vcxproj +++ b/build/libjin/libjin.vcxproj @@ -126,7 +126,7 @@      <ProjectGuid>{407E9199-D39C-4460-B218-0C29AB42483B}</ProjectGuid>      <Keyword>Win32Proj</Keyword>      <RootNamespace>libjin</RootNamespace> -    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> +    <WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>    </PropertyGroup>    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> diff --git a/libjin/Graphics/Font.cpp b/libjin/Graphics/Font.cpp index 9d21dba..c1afd53 100644 --- a/libjin/Graphics/Font.cpp +++ b/libjin/Graphics/Font.cpp @@ -118,40 +118,49 @@ namespace graphics      void Font::print(const char* t, int x, int y)      { -        // typesetting  -        vector<GlyphArrayDrawInfo> glyphinfolist; -        vector<GlyphVertex> glyphvertices; +        Page* page = typeset(t, x, y);  +        render(page); +        delete page; +    } + +    Page* Font::typeset(const char* t, int x, int y) +    { +        // typesetting +        Page* page = new Page(); +        vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist; +        vector<GlyphVertex>& glyphvertices = page->glyphvertices;          Vector2<int> p(x, y);          Codepoint c;          int texture = -1;          Glyph* glyph = nullptr;          GlyphVertex vertex; -        for(int i = 0; *t != NULL; i+=4) +        for (int i = 0; *t != NULL; i += 4)          {              t = utf8toCodepoint(t, &c); -            if (c == 0x0D) continue; -            /* new line */  +            if (c == 0x0D)  +                continue; +            /* new line */              if (c == 0x0A)              {                  p.y += descent; -                p.x = 0; +                p.x = x;                  continue;              }              glyph = findGlyph(c);              if (texture != glyph->atlas)              {                  GlyphArrayDrawInfo info; -                info.start = i;  -                info.count = 0;  -                info.texture = glyph->atlas;  +                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; +            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; @@ -162,19 +171,24 @@ namespace graphics              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; +            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;          } +        return page; +    } -        // draw  +    void Font::render(const Page* page) +    { +        const vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist; +        const vector<GlyphVertex>& glyphvertices = page->glyphvertices;          glEnableClientState(GL_VERTEX_ARRAY);          glEnableClientState(GL_TEXTURE_COORD_ARRAY);          for (int i = 0; i < glyphinfolist.size(); ++i)          { -            GlyphArrayDrawInfo& info = glyphinfolist[i]; +            const GlyphArrayDrawInfo& info = glyphinfolist[i];              glBindTexture(GL_TEXTURE_2D, info.texture);              glVertexPointer(2, GL_INT, sizeof(GlyphVertex), &glyphvertices[info.start].x);              glTexCoordPointer(2, GL_FLOAT, sizeof(GlyphVertex), &glyphvertices[info.start].u); @@ -188,14 +202,14 @@ namespace graphics          glBindTexture(GL_TEXTURE_2D, 1);          float xy[] = {              0,0, -            0,textureHeight,  +            0,textureHeight,              textureWidth, textureHeight,              textureWidth, 0          };          float uv[] = {              0, 0,              0, 1, -            1, 1,  +            1, 1,              1, 0          };          glVertexPointer(2, GL_FLOAT, 0, xy); diff --git a/libjin/Graphics/Font.h b/libjin/Graphics/Font.h index a39e6a6..e944b41 100644 --- a/libjin/Graphics/Font.h +++ b/libjin/Graphics/Font.h @@ -40,6 +40,12 @@ namespace graphics          unsigned int width, height;      }; +    struct Page +    { +        std::vector<GlyphArrayDrawInfo> glyphinfolist; +        std::vector<GlyphVertex> glyphvertices; +    }; +      class Font      {      public: @@ -48,6 +54,8 @@ namespace graphics          static Font* createFont(FontData* fontData, unsigned int fontSzie);          void print(const char* text, int x, int y); +        Page* typeset(const char* text, int x, int y); +        void render(const Page* page);  #if defined(font_debug)          void drawAtlas();  #endif diff --git a/libjin/Graphics/Mesh.cpp b/libjin/Graphics/Mesh.cpp index e69de29..503a189 100644 --- a/libjin/Graphics/Mesh.cpp +++ b/libjin/Graphics/Mesh.cpp @@ -0,0 +1,11 @@ +#include "Mesh.h" + +namespace jin +{ +namespace graphics +{ + + + +} +}
\ No newline at end of file diff --git a/libjin/Graphics/Mesh.h b/libjin/Graphics/Mesh.h index 6f70f09..d0bb93e 100644 --- a/libjin/Graphics/Mesh.h +++ b/libjin/Graphics/Mesh.h @@ -1 +1,17 @@ -#pragma once +#ifndef __LIBJIN_MESH_H +#define __LIBJIN_MESH_H + +namespace jin +{ +namespace graphics +{ + +    class Mesh +    { + +    }; + +} +} + +#endif
\ No newline at end of file diff --git a/libjin/Graphics/OpenGL.h b/libjin/Graphics/OpenGL.h index f73650b..2f087be 100644 --- a/libjin/Graphics/OpenGL.h +++ b/libjin/Graphics/OpenGL.h @@ -1,5 +1,8 @@  #ifndef __LIBJIN_OPENGL_H  #define __LIBJIN_OPENGL_H +#include <vector> +#include "../3rdparty/GLee/GLee.h" +#include "Color.h"  namespace jin  { @@ -10,9 +13,19 @@ namespace graphics      class OpenGL      {      public:  -        void bindTexture(); +        OpenGL(); + +        void bindTexture(GLuint texture); + +    private:  +        std::vector<Color> color; + +        ~OpenGL();      }; +     +    /* OpenGL instance singleton */ +    extern OpenGL gl;  }  } diff --git a/test/05Font/main.cpp b/test/05Font/main.cpp index 1388537..78a1142 100644 --- a/test/05Font/main.cpp +++ b/test/05Font/main.cpp @@ -17,19 +17,17 @@ void onLoad()  uniform float dt;   Color effect(Color col, Texture tex, vec2 uv, vec2 screen)  { -    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); +    float a = Texel(tex, uv).a; +    return Color(col.rgb, a/5);  }      )";      shader = JSLProgram::createJSLProgram(program);      Filesystem* fs = Filesystem::get();      fs->mount("../Debug");      Buffer buffer; -    fs->read("font.ttf", &buffer); +    fs->read("simhei.ttf", &buffer);      data = FontData::createFontData((const unsigned char*)buffer.data, buffer.size); -    font = Font::createFont(data, 17); +    font = Font::createFont(data, 14);      //canvas = Canvas::createCanvas(100, 100);  } @@ -56,10 +54,10 @@ void onDraw()      if (font != nullptr)      {          glColor4f(1, 1, 1, 1); -        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); +        font->print(u8"Hello,你好\n啊 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();  | 
