diff --git a/glyphs/font_atlas.go b/glyphs/font_atlas.go index 933303d..2e1b2c4 100755 --- a/glyphs/font_atlas.go +++ b/glyphs/font_atlas.go @@ -148,8 +148,7 @@ func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*Fo drawer.Dot = fixed.P(0, lineHeight) for _, g := range glyphs { - gBounds, gAdvanceFixed, _ := face.GlyphBounds(g) - + gBounds, _, _ := face.GlyphBounds(g) ascent := absFixedI26_6(gBounds.Min.Y) descent := absFixedI26_6(gBounds.Max.Y) bearingX := absFixedI26_6(gBounds.Min.X) @@ -165,7 +164,7 @@ func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*Fo //Get glyph to draw but undo any applied descent so that the glyph is drawn sitting on the line exactly. //Bearing will be applied correctly but descent will be the responsibility of the positioning code - imgRect, mask, maskp, _, _ := face.Glyph(drawer.Dot, g) + imgRect, mask, maskp, gAdvanceFixed, _ := face.Glyph(drawer.Dot, g) if imgRect.Max.Y > drawer.Dot.Y.Ceil() { diff := imgRect.Max.Y - drawer.Dot.Y.Ceil() imgRect.Min.Y -= diff diff --git a/glyphs/glyphs.go b/glyphs/glyphs.go index abf69fe..223739e 100755 --- a/glyphs/glyphs.go +++ b/glyphs/glyphs.go @@ -64,7 +64,7 @@ func (gr *GlyphRend) DrawTextOpenGLAbs(text string, screenPos *gglm.Vec3, color } gr.GlyphCount++ - scale := gglm.NewVec3(advanceF32, lineHeightF32, 1) + scale := gglm.NewVec2(advanceF32, lineHeightF32) //See: https://developer.apple.com/library/archive/documentation/TextFonts/Conceptual/CocoaTextArchitecture/Art/glyph_metrics_2x.png //The uvs coming in make it so that glyphs are sitting on top of the baseline (no descent) and with horizontal bearing applied. @@ -77,7 +77,7 @@ func (gr *GlyphRend) DrawTextOpenGLAbs(text string, screenPos *gglm.Vec3, color g.U, g.V, color.R(), color.G(), color.B(), color.A(), //Color roundF32(drawPos.X()), roundF32(drawPos.Y()), drawPos.Z(), //Model pos - scale.X(), scale.Y(), scale.Z(), //Model scale + scale.X(), scale.Y(), //Model scale }...) pos.SetX(pos.X() + advanceF32) @@ -253,7 +253,7 @@ func NewGlyphRend(fontFile string, fontOptions *truetype.Options, screenWidth, s buffers.Element{ElementType: buffers.DataTypeVec2}, //UV0 buffers.Element{ElementType: buffers.DataTypeVec4}, //Color buffers.Element{ElementType: buffers.DataTypeVec3}, //ModelPos - buffers.Element{ElementType: buffers.DataTypeVec3}, //ModelScale + buffers.Element{ElementType: buffers.DataTypeVec2}, //ModelScale ) gr.InstancedBuf.Bind() diff --git a/res/shaders/glyph.glsl b/res/shaders/glyph.glsl index 17b2aac..a3823f1 100755 --- a/res/shaders/glyph.glsl +++ b/res/shaders/glyph.glsl @@ -3,29 +3,31 @@ //aVertPos must be in the range [0,1] layout(location=0) in vec3 aVertPos; + +//Instanced layout(location=1) in vec2 aUV0; layout(location=2) in vec4 aVertColor; layout(location=3) in vec3 aModelPos; -layout(location=4) in vec3 aModelScale; +layout(location=4) in vec2 aModelScale; out vec2 v2fUV0; out vec4 v2fColor; out vec3 v2fFragPos; -//MVP = Model View Projection uniform mat4 projViewMat; +uniform vec2 modelSize; uniform vec2 sizeUV; void main() { mat4 modelMat = mat4( - aModelScale.x, 0.0, 0.0, 0.0, - 0.0, aModelScale.y, 0.0, 0.0, - 0.0, 0.0, aModelScale.z, 0.0, - aModelPos.x, aModelPos.y, aModelPos.z, 1.0 + aModelScale.x, 0.0, 0.0, 0.0, + 0.0, aModelScale.y, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + aModelPos.x, aModelPos.y, aModelPos.z, 1.0 ); - v2fUV0 = aUV0 + sizeUV*aVertPos.xy; + v2fUV0 = aUV0 + aVertPos.xy * sizeUV; v2fColor = aVertColor; v2fFragPos = vec3(modelMat * vec4(aVertPos, 1.0));