2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-07-02 05:33:27 +00:00

Working font rendering

This commit is contained in:
Jack Andersen 2015-11-26 13:03:56 -10:00
parent a0fd785b5b
commit ecbed6e82c
7 changed files with 67 additions and 36 deletions

View File

@ -56,7 +56,7 @@ class FontAtlas
{
friend class FontCache;
FT_Face m_face;
boo::ITextureS* m_tex;
boo::ITextureSA* m_tex;
uint32_t m_dpi;
FT_Fixed m_ftXscale;
FT_UShort m_ftXPpem;
@ -68,12 +68,12 @@ public:
atUint32 m_layerIdx;
float m_layerFloat;
float m_uv[4];
atInt8 m_leftPadding;
atInt8 m_advance;
atInt8 m_rightPadding;
atUint8 m_width;
atUint8 m_height;
atInt8 m_verticalOffset;
atInt32 m_leftPadding;
atInt32 m_advance;
atInt32 m_rightPadding;
atUint32 m_width;
atUint32 m_height;
atInt32 m_verticalOffset;
};
private:

View File

@ -17,9 +17,14 @@ class RootView : public View, public boo::IWindowCallback
TextView m_textView;
boo::SWindowRect m_rootRect;
bool m_resizeRTDirty = false;
bool m_destroyed = false;
public:
void destroyed();
bool isDestroyed() const {return m_destroyed;}
void resized(const boo::SWindowRect& rect);
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
void mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mods);
void mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mods);
void mouseMove(const boo::SWindowCoord& coord);
@ -40,7 +45,6 @@ public:
void draw(boo::IGraphicsCommandQueue* gfxQ);
public:
RootView(ViewSystem& system, boo::IWindow* window);
};

View File

@ -29,6 +29,13 @@ protected:
struct VertexBlock
{
Zeus::CMatrix4f m_mv;
void setViewRect(const boo::SWindowRect& root, const boo::SWindowRect& sub)
{
m_mv[0][0] = 2.0f / root.size[0];
m_mv[1][1] = 2.0f / root.size[1];
m_mv[3][0] = sub.location[0] * m_mv[0][0] - 1.0f;
m_mv[3][1] = sub.location[1] * m_mv[1][1] - 1.0f;
}
} m_viewVertBlock;
#define SPECTER_VIEW_VERT_BLOCK_GLSL\
"uniform SpecterViewBlock\n"\
@ -57,8 +64,9 @@ protected:
View(ViewSystem& system);
public:
View() = delete;
void setBackground(Zeus::CColor color) {m_bgColor = color; m_bgValidSlots = 0;}
virtual void resized(const boo::SWindowRect& rect);
virtual void resized(const boo::SWindowRect &root, const boo::SWindowRect& sub);
virtual void draw(boo::IGraphicsCommandQueue* gfxQ);
};

View File

@ -256,10 +256,10 @@ FontAtlas::FontAtlas(boo::IGraphicsDataFactory* gf, FT_Face face, uint32_t dpi,
g.m_uv[1] = totalHeight / float(finalHeight);
g.m_uv[2] = g.m_uv[0] + g.m_width / float(TEXMAP_DIM);
g.m_uv[3] = g.m_uv[1] + g.m_height / float(finalHeight);
g.m_leftPadding = 0;
g.m_advance = face->glyph->advance.x;
g.m_leftPadding = face->glyph->metrics.horiBearingX >> 6;
g.m_advance = face->glyph->advance.x >> 6;
g.m_rightPadding = 0;
g.m_verticalOffset = face->glyph->metrics.horiBearingY / 64;
g.m_verticalOffset = (face->glyph->metrics.horiBearingY - face->glyph->metrics.height) >> 6;
if (curLineWidth + g.m_width + 1 > TEXMAP_DIM)
{
totalHeight += curLineHeight + 1;
@ -327,10 +327,10 @@ FontAtlas::FontAtlas(boo::IGraphicsDataFactory* gf, FT_Face face, uint32_t dpi,
g.m_uv[1] = totalHeight / float(finalHeight);
g.m_uv[2] = g.m_uv[0] + g.m_width / float(TEXMAP_DIM);
g.m_uv[3] = g.m_uv[1] + g.m_height / float(finalHeight);
g.m_leftPadding = 0;
g.m_advance = face->glyph->advance.x;
g.m_leftPadding = face->glyph->metrics.horiBearingX >> 6;
g.m_advance = face->glyph->advance.x >> 6;
g.m_rightPadding = 0;
g.m_verticalOffset = face->glyph->metrics.horiBearingY >> 6;
g.m_verticalOffset = (face->glyph->metrics.horiBearingY - face->glyph->metrics.height) >> 6;
if (curLineWidth + g.m_width + 1 > TEXMAP_DIM)
{
totalHeight += curLineHeight + 1;
@ -431,10 +431,10 @@ FontAtlas::FontAtlas(boo::IGraphicsDataFactory* gf, FT_Face face, uint32_t dpi,
g.m_uv[1] = totalHeight / float(finalHeight);
g.m_uv[2] = g.m_uv[0] + g.m_width / float(TEXMAP_DIM);
g.m_uv[3] = g.m_uv[1] + g.m_height / float(finalHeight);
g.m_leftPadding = 0;
g.m_advance = face->glyph->advance.x;
g.m_leftPadding = face->glyph->metrics.horiBearingX >> 6;
g.m_advance = face->glyph->advance.x >> 6;
g.m_rightPadding = 0;
g.m_verticalOffset = face->glyph->metrics.horiBearingY / 64;
g.m_verticalOffset = (face->glyph->metrics.horiBearingY - face->glyph->metrics.height) >> 6;
if (curLineWidth + g.m_width + 1 > TEXMAP_DIM)
{
totalHeight += curLineHeight + 1;
@ -502,10 +502,10 @@ FontAtlas::FontAtlas(boo::IGraphicsDataFactory* gf, FT_Face face, uint32_t dpi,
g.m_uv[1] = totalHeight / float(finalHeight);
g.m_uv[2] = g.m_uv[0] + g.m_width / float(TEXMAP_DIM);
g.m_uv[3] = g.m_uv[1] + g.m_height / float(finalHeight);
g.m_leftPadding = 0;
g.m_advance = face->glyph->advance.x;
g.m_leftPadding = face->glyph->metrics.horiBearingX >> 6;
g.m_advance = face->glyph->advance.x >> 6;
g.m_rightPadding = 0;
g.m_verticalOffset = face->glyph->metrics.horiBearingY >> 6;
g.m_verticalOffset = (face->glyph->metrics.horiBearingY - face->glyph->metrics.height) >> 6;
if (curLineWidth + g.m_width + 1 > TEXMAP_DIM)
{
totalHeight += curLineHeight + 1;

View File

@ -7,19 +7,33 @@ namespace Specter
RootView::RootView(ViewSystem& system, boo::IWindow* window)
: View(system), m_window(window), m_textView(system, system.m_mainFont)
{
window->setCallback(this);
boo::SWindowRect rect = window->getWindowFrame();
m_renderTex = system.m_factory->newRenderTexture(rect.size[0], rect.size[1], 1);
system.m_factory->commit();
resized(rect);
m_textView.typesetGlyphs("Hello, World!");
m_textView.typesetGlyphs("Hello, World! — こんにちは世界!", Zeus::CColor::skGreen);
Zeus::CColor transBlack(0.f, 0.f, 0.f, 0.5f);
m_textView.setBackground(transBlack);
setBackground(Zeus::CColor::skBlue);
}
void RootView::destroyed()
{
m_destroyed = true;
}
void RootView::resized(const boo::SWindowRect& rect)
{
m_rootRect = rect;
resized(rect, rect);
}
void RootView::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
{
m_rootRect = root;
m_rootRect.location[0] = 0;
m_rootRect.location[1] = 0;
View::resized(m_rootRect);
View::resized(m_rootRect, m_rootRect);
boo::SWindowRect textRect = m_rootRect;
textRect.location[0] = 10;
textRect.location[1] = 10;
@ -27,7 +41,7 @@ void RootView::resized(const boo::SWindowRect& rect)
if (textRect.size[0] < 0)
textRect.size[0] = 0;
textRect.size[1] = 10;
m_textView.resized(textRect);
m_textView.resized(m_rootRect, textRect);
m_resizeRTDirty = true;
}
@ -94,7 +108,10 @@ void RootView::modKeyUp(boo::EModifierKey mod)
void RootView::draw(boo::IGraphicsCommandQueue* gfxQ)
{
if (m_resizeRTDirty)
{
gfxQ->resizeRenderTexture(m_renderTex, m_rootRect.size[0], m_rootRect.size[1]);
m_resizeRTDirty = false;
}
gfxQ->setRenderTarget(m_renderTex);
gfxQ->setViewport(m_rootRect);
View::draw(gfxQ);

View File

@ -71,12 +71,12 @@ void TextView::System::init(boo::GLDataFactory* factory, FontCache* fcache)
m_regular =
factory->newShaderPipeline(VS, FSReg, 1, "fontTex", 1, BlockNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
true, true, false);
false, false, false);
m_subpixel =
factory->newShaderPipeline(VS, FSSubpixel, 1, "fontTex", 1, BlockNames,
boo::BlendFactor::SrcColor1, boo::BlendFactor::InvSrcColor1,
true, true, false);
false, false, false);
}
TextView::TextView(ViewSystem& system, FontTag font, size_t capacity)
@ -143,7 +143,7 @@ static int DoKern(FT_Pos val, const FontAtlas& atlas)
if (atlas.FT_XPPem() < 25)
val = FT_MulDiv(orig_x, atlas.FT_XPPem(), 25);
return FT_PIX_ROUND(val);
return FT_PIX_ROUND(val) >> 6;
}
void TextView::typesetGlyphs(const std::string& str, const Zeus::CColor& defaultColor)
@ -174,7 +174,7 @@ void TextView::typesetGlyphs(const std::string& str, const Zeus::CColor& default
if (lCh != -1)
{
adv += m_fontAtlas.lookupKern(lCh, ch);
adv += DoKern(m_fontAtlas.lookupKern(lCh, ch), m_fontAtlas);
m_glyphs.emplace_back(adv, *glyph, defaultColor);
}
else
@ -246,6 +246,7 @@ void TextView::draw(boo::IGraphicsCommandQueue* gfxQ)
m_validSlots |= pendingSlot;
}
gfxQ->setShaderDataBinding(m_shaderBinding);
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
gfxQ->drawInstances(0, 4, m_glyphs.size());
}

View File

@ -19,7 +19,7 @@ void View::System::init(boo::GLDataFactory* factory)
"void main()\n"
"{\n"
" vtf.color = colorIn;\n"
" gl_Position = mv * vec4(posIn[gl_VertexID], 1.0);\n"
" gl_Position = mv * vec4(posIn, 1.0);\n"
"}\n";
static const char* FS =
@ -73,13 +73,13 @@ View::View(ViewSystem& system)
}
void View::resized(const boo::SWindowRect& rect)
void View::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
{
m_viewVertBlock.m_mv[3].assign(rect.location[0], rect.location[1], 0.f, 1.f);
m_bgRect[0].assign(0.f, rect.size[1], 0.f);
m_bgRect[1].assign(0.f, rect.size[1], 0.f);
m_bgRect[2].assign(0.f, rect.size[1], 0.f);
m_bgRect[3].assign(0.f, rect.size[1], 0.f);
m_viewVertBlock.setViewRect(root, sub);
m_bgRect[0].assign(0.f, sub.size[1], 0.f);
m_bgRect[1].assign(0.f, 0.f, 0.f);
m_bgRect[2].assign(sub.size[0], sub.size[1], 0.f);
m_bgRect[3].assign(sub.size[0], 0.f, 0.f);
m_bgValidSlots = 0;
}
@ -94,6 +94,7 @@ void View::draw(boo::IGraphicsCommandQueue* gfxQ)
m_bgValidSlots |= pendingSlot;
}
gfxQ->setShaderDataBinding(m_bgShaderBinding);
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
gfxQ->draw(0, 4);
}