Use accurate space advance+correct grid drawing

This commit is contained in:
bloeys
2022-07-11 09:41:58 +04:00
parent dec853adca
commit 908ff7e562
2 changed files with 4 additions and 5 deletions

View File

@ -152,7 +152,7 @@ func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*Fo
Img: image.NewRGBA(image.Rect(0, 0, atlasSizeX, atlasSizeY)), Img: image.NewRGBA(image.Rect(0, 0, atlasSizeX, atlasSizeY)),
Glyphs: make(map[rune]FontAtlasGlyph, len(glyphs)), Glyphs: make(map[rune]FontAtlasGlyph, len(glyphs)),
SpaceAdvance: float32(spaceAdv.Ceil()), SpaceAdvance: I26_6ToF32(spaceAdv),
LineHeight: float32(lineHeight.Ceil()), LineHeight: float32(lineHeight.Ceil()),
} }
@ -165,8 +165,7 @@ func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*Fo
} }
//Put glyphs on atlas //Put glyphs on atlas
drawer.Dot = fixed.P(int(atlas.SpaceAdvance), 0) drawer.Dot.X = spaceAdv + charPaddingXFixed
drawer.Dot.X += charPaddingXFixed
drawer.Dot.Y = lineHeight drawer.Dot.Y = lineHeight
const drawBoundingBoxes bool = false const drawBoundingBoxes bool = false

View File

@ -249,8 +249,8 @@ func (p *program) drawGrid() {
//columns //columns
adv := p.GlyphRend.Atlas.SpaceAdvance adv := p.GlyphRend.Atlas.SpaceAdvance
for i := int32(0); i < p.GlyphRend.ScreenWidth; i += int32(adv) { for i := 0; i < int(p.GlyphRend.ScreenWidth); i++ {
p.rend.Draw(p.gridMesh, gglm.NewTrMatId().Translate(gglm.NewVec3(float32(i)+0.5, sizeY/2, 0)).Scale(gglm.NewVec3(1, sizeY, 1)), p.gridMat) p.rend.Draw(p.gridMesh, gglm.NewTrMatId().Translate(gglm.NewVec3(adv*float32(i), sizeY/2, 0)).Scale(gglm.NewVec3(1, sizeY, 1)), p.gridMat)
} }
//rows //rows