mirror of
https://github.com/bloeys/nterm.git
synced 2025-12-29 14:38:19 +00:00
Use vec2 for glyph model scale
This commit is contained in:
@ -148,8 +148,7 @@ func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*Fo
|
|||||||
drawer.Dot = fixed.P(0, lineHeight)
|
drawer.Dot = fixed.P(0, lineHeight)
|
||||||
for _, g := range glyphs {
|
for _, g := range glyphs {
|
||||||
|
|
||||||
gBounds, gAdvanceFixed, _ := face.GlyphBounds(g)
|
gBounds, _, _ := face.GlyphBounds(g)
|
||||||
|
|
||||||
ascent := absFixedI26_6(gBounds.Min.Y)
|
ascent := absFixedI26_6(gBounds.Min.Y)
|
||||||
descent := absFixedI26_6(gBounds.Max.Y)
|
descent := absFixedI26_6(gBounds.Max.Y)
|
||||||
bearingX := absFixedI26_6(gBounds.Min.X)
|
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.
|
//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
|
//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() {
|
if imgRect.Max.Y > drawer.Dot.Y.Ceil() {
|
||||||
diff := imgRect.Max.Y - drawer.Dot.Y.Ceil()
|
diff := imgRect.Max.Y - drawer.Dot.Y.Ceil()
|
||||||
imgRect.Min.Y -= diff
|
imgRect.Min.Y -= diff
|
||||||
|
|||||||
@ -64,7 +64,7 @@ func (gr *GlyphRend) DrawTextOpenGLAbs(text string, screenPos *gglm.Vec3, color
|
|||||||
}
|
}
|
||||||
gr.GlyphCount++
|
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
|
//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.
|
//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,
|
g.U, g.V,
|
||||||
color.R(), color.G(), color.B(), color.A(), //Color
|
color.R(), color.G(), color.B(), color.A(), //Color
|
||||||
roundF32(drawPos.X()), roundF32(drawPos.Y()), drawPos.Z(), //Model pos
|
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)
|
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.DataTypeVec2}, //UV0
|
||||||
buffers.Element{ElementType: buffers.DataTypeVec4}, //Color
|
buffers.Element{ElementType: buffers.DataTypeVec4}, //Color
|
||||||
buffers.Element{ElementType: buffers.DataTypeVec3}, //ModelPos
|
buffers.Element{ElementType: buffers.DataTypeVec3}, //ModelPos
|
||||||
buffers.Element{ElementType: buffers.DataTypeVec3}, //ModelScale
|
buffers.Element{ElementType: buffers.DataTypeVec2}, //ModelScale
|
||||||
)
|
)
|
||||||
|
|
||||||
gr.InstancedBuf.Bind()
|
gr.InstancedBuf.Bind()
|
||||||
|
|||||||
@ -3,29 +3,31 @@
|
|||||||
|
|
||||||
//aVertPos must be in the range [0,1]
|
//aVertPos must be in the range [0,1]
|
||||||
layout(location=0) in vec3 aVertPos;
|
layout(location=0) in vec3 aVertPos;
|
||||||
|
|
||||||
|
//Instanced
|
||||||
layout(location=1) in vec2 aUV0;
|
layout(location=1) in vec2 aUV0;
|
||||||
layout(location=2) in vec4 aVertColor;
|
layout(location=2) in vec4 aVertColor;
|
||||||
layout(location=3) in vec3 aModelPos;
|
layout(location=3) in vec3 aModelPos;
|
||||||
layout(location=4) in vec3 aModelScale;
|
layout(location=4) in vec2 aModelScale;
|
||||||
|
|
||||||
out vec2 v2fUV0;
|
out vec2 v2fUV0;
|
||||||
out vec4 v2fColor;
|
out vec4 v2fColor;
|
||||||
out vec3 v2fFragPos;
|
out vec3 v2fFragPos;
|
||||||
|
|
||||||
//MVP = Model View Projection
|
|
||||||
uniform mat4 projViewMat;
|
uniform mat4 projViewMat;
|
||||||
|
uniform vec2 modelSize;
|
||||||
uniform vec2 sizeUV;
|
uniform vec2 sizeUV;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
mat4 modelMat = mat4(
|
mat4 modelMat = mat4(
|
||||||
aModelScale.x, 0.0, 0.0, 0.0,
|
aModelScale.x, 0.0, 0.0, 0.0,
|
||||||
0.0, aModelScale.y, 0.0, 0.0,
|
0.0, aModelScale.y, 0.0, 0.0,
|
||||||
0.0, 0.0, aModelScale.z, 0.0,
|
0.0, 0.0, 1.0, 0.0,
|
||||||
aModelPos.x, aModelPos.y, aModelPos.z, 1.0
|
aModelPos.x, aModelPos.y, aModelPos.z, 1.0
|
||||||
);
|
);
|
||||||
|
|
||||||
v2fUV0 = aUV0 + sizeUV*aVertPos.xy;
|
v2fUV0 = aUV0 + aVertPos.xy * sizeUV;
|
||||||
v2fColor = aVertColor;
|
v2fColor = aVertColor;
|
||||||
v2fFragPos = vec3(modelMat * vec4(aVertPos, 1.0));
|
v2fFragPos = vec3(modelMat * vec4(aVertPos, 1.0));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user