mirror of
https://github.com/bloeys/nterm.git
synced 2025-12-29 14:38:19 +00:00
Advance by char width+better debug tools
This commit is contained in:
@ -35,6 +35,7 @@ type FontAtlasGlyph struct {
|
|||||||
Ascent float32
|
Ascent float32
|
||||||
Descent float32
|
Descent float32
|
||||||
BearingX float32
|
BearingX float32
|
||||||
|
Advance float32
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewFontAtlasFromFile reads a TTF or TTC file and produces a font texture atlas containing
|
//NewFontAtlasFromFile reads a TTF or TTC file and produces a font texture atlas containing
|
||||||
@ -149,7 +150,7 @@ func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*Fo
|
|||||||
|
|
||||||
for currGlyphCount, g := range glyphs {
|
for currGlyphCount, g := range glyphs {
|
||||||
|
|
||||||
gBounds, _, _ := face.GlyphBounds(g)
|
gBounds, gAdvance, _ := face.GlyphBounds(g)
|
||||||
bearingX := gBounds.Min.X
|
bearingX := gBounds.Min.X
|
||||||
ascentAbsFixed := absFixedI26_6(gBounds.Min.Y)
|
ascentAbsFixed := absFixedI26_6(gBounds.Min.Y)
|
||||||
descentAbsFixed := absFixedI26_6(gBounds.Max.Y)
|
descentAbsFixed := absFixedI26_6(gBounds.Max.Y)
|
||||||
@ -174,6 +175,7 @@ func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*Fo
|
|||||||
Ascent: float32(ascentAbsFixed.Ceil()),
|
Ascent: float32(ascentAbsFixed.Ceil()),
|
||||||
Descent: float32(descentAbsFixed.Ceil()),
|
Descent: float32(descentAbsFixed.Ceil()),
|
||||||
BearingX: float32(bearingX.Ceil()),
|
BearingX: float32(bearingX.Ceil()),
|
||||||
|
Advance: float32(gAdvance.Ceil()),
|
||||||
}
|
}
|
||||||
|
|
||||||
imgRect, mask, maskp, _, _ := face.Glyph(drawer.Dot, g)
|
imgRect, mask, maskp, _, _ := face.Glyph(drawer.Dot, g)
|
||||||
|
|||||||
@ -178,15 +178,13 @@ func (gr *GlyphRend) drawRune(rs []rune, i int, prevRune rune, screenPos, pos *g
|
|||||||
*bufIndex += 2
|
*bufIndex += 2
|
||||||
|
|
||||||
gr.GlyphCount++
|
gr.GlyphCount++
|
||||||
pos.AddX(advanceF32)
|
pos.AddX(g.Advance)
|
||||||
|
|
||||||
//If we fill the buffer we issue a draw call
|
//If we fill the buffer we issue a draw call
|
||||||
if gr.GlyphCount == MaxGlyphsPerBatch {
|
if gr.GlyphCount == MaxGlyphsPerBatch {
|
||||||
gr.Draw()
|
gr.Draw()
|
||||||
*bufIndex = 0
|
*bufIndex = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// prevRune = r
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gr *GlyphRend) GetTextRuns(t string) [][]rune {
|
func (gr *GlyphRend) GetTextRuns(t string) [][]rune {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
[Window][Debug##Default]
|
[Window][Debug##Default]
|
||||||
Pos=814,53
|
Pos=814,53
|
||||||
Size=405,63
|
Size=396,114
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
|
|||||||
28
main.go
28
main.go
@ -106,13 +106,6 @@ func (p *program) Init() {
|
|||||||
|
|
||||||
p.gridMat = materials.NewMaterial("grid", "./res/shaders/grid.glsl")
|
p.gridMat = materials.NewMaterial("grid", "./res/shaders/grid.glsl")
|
||||||
p.handleWindowResize()
|
p.handleWindowResize()
|
||||||
|
|
||||||
// runs := p.GlyphRend.GetTextRuns("hello there يا friend. أسمي عمر wow")
|
|
||||||
// runs := p.GlyphRend.GetTextRuns("hello there my friend!")
|
|
||||||
// fmt.Printf("%+v\n", runs)
|
|
||||||
// for _, r := range runs {
|
|
||||||
// fmt.Printf("%s;\n", string(r))
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *program) Update() {
|
func (p *program) Update() {
|
||||||
@ -167,10 +160,29 @@ func (p *program) Update() {
|
|||||||
p.shouldDrawGrid = !p.shouldDrawGrid
|
p.shouldDrawGrid = !p.shouldDrawGrid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//UI
|
||||||
imgui.InputText("", &textToShow)
|
imgui.InputText("", &textToShow)
|
||||||
|
|
||||||
|
if imgui.Button("Print Runs") {
|
||||||
|
runs := p.GlyphRend.GetTextRuns(textToShow)
|
||||||
|
for _, r := range runs {
|
||||||
|
fmt.Printf("%s; runes: %#x\n\n", string(r), r)
|
||||||
|
}
|
||||||
|
fmt.Printf("----------------\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
var textToShow = " Hello there يا friend. أسمي عمر wow!"
|
if imgui.Checkbox("Draw Bounds", &isDrawingBounds) {
|
||||||
|
|
||||||
|
if isDrawingBounds {
|
||||||
|
p.GlyphRend.GlyphMat.SetUnifInt32("drawBounds", 1)
|
||||||
|
} else {
|
||||||
|
p.GlyphRend.GlyphMat.SetUnifInt32("drawBounds", 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var isDrawingBounds = false
|
||||||
|
var textToShow = " Hello there يا friend. اسمي عمر wow!"
|
||||||
|
|
||||||
var xOff float32 = 0
|
var xOff float32 = 0
|
||||||
var yOff float32 = 0
|
var yOff float32 = 0
|
||||||
|
|||||||
@ -42,16 +42,17 @@ in vec4 v2fColor;
|
|||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D diffTex;
|
uniform sampler2D diffTex;
|
||||||
|
uniform int drawBounds;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 texColor = texelFetch(diffTex, ivec2(v2fUV0), 0);
|
vec4 texColor = texelFetch(diffTex, ivec2(v2fUV0), 0);
|
||||||
// This commented out part highlights the full region of the char
|
// This commented out part highlights the full region of the char
|
||||||
// if (texColor.r == 0)
|
if (texColor.r == 0 && drawBounds != 0)
|
||||||
// {
|
{
|
||||||
// fragColor = vec4(0,1,0,0.25);
|
fragColor = vec4(0,1,0,0.25);
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
{
|
{
|
||||||
fragColor = vec4(v2fColor.rgb, texColor.r*v2fColor.a);
|
fragColor = vec4(v2fColor.rgb, texColor.r*v2fColor.a);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user