mirror of
https://github.com/bloeys/nterm.git
synced 2025-12-29 06:28:20 +00:00
Correct alpha handling in glyph shader
This commit is contained in:
27
main.go
27
main.go
@ -10,10 +10,8 @@ import (
|
||||
"github.com/bloeys/nmage/materials"
|
||||
"github.com/bloeys/nmage/meshes"
|
||||
"github.com/bloeys/nmage/renderer/rend3dgl"
|
||||
"github.com/bloeys/nmage/timing"
|
||||
nmageimgui "github.com/bloeys/nmage/ui/imgui"
|
||||
"github.com/bloeys/nterm/glyphs"
|
||||
"github.com/go-gl/gl/v4.1-core/gl"
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"golang.org/x/image/font"
|
||||
@ -73,7 +71,6 @@ func main() {
|
||||
})
|
||||
|
||||
//Don't flash white
|
||||
gl.ClearColor(0, 0, 0, 0)
|
||||
p.win.SDLWin.GLSwap()
|
||||
|
||||
engine.Run(p, p.win, p.imguiInfo)
|
||||
@ -156,12 +153,8 @@ func (p *program) Update() {
|
||||
if input.KeyClicked(sdl.K_SPACE) {
|
||||
p.shouldDrawGrid = !p.shouldDrawGrid
|
||||
}
|
||||
|
||||
fmt.Println("FPS:", int(timing.GetAvgFPS()), "; Draws per frame:", charsPerFrame/16384)
|
||||
}
|
||||
|
||||
const charsPerFrame = 100_000
|
||||
|
||||
var xOff float32 = 0
|
||||
var yOff float32 = 0
|
||||
|
||||
@ -172,8 +165,13 @@ var b = rand.Float32()
|
||||
func (p *program) Render() {
|
||||
|
||||
const colorSpd = 0.005
|
||||
// const charsPerFrame = 100_000
|
||||
defer p.GlyphRend.Draw()
|
||||
|
||||
if p.shouldDrawGrid {
|
||||
p.drawGrid()
|
||||
}
|
||||
|
||||
r += colorSpd
|
||||
if r > 1 {
|
||||
r = 0
|
||||
@ -190,17 +188,16 @@ func (p *program) Render() {
|
||||
}
|
||||
|
||||
textColor := gglm.NewVec4(r, g, b, 1)
|
||||
|
||||
str := " ijojo\n\n Hello there, friend|. pq?\n ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
strLen := len(str)
|
||||
|
||||
for i := 0; i < charsPerFrame/strLen; i++ {
|
||||
p.GlyphRend.DrawTextOpenGLAbs(str, gglm.NewVec3(xOff, float32(p.GlyphRend.Atlas.LineHeight)*5+yOff, 0), textColor)
|
||||
}
|
||||
p.GlyphRend.DrawTextOpenGLAbs(str, gglm.NewVec3(xOff, float32(p.GlyphRend.Atlas.LineHeight)*5+yOff, 0), textColor)
|
||||
|
||||
if p.shouldDrawGrid {
|
||||
p.drawGrid()
|
||||
}
|
||||
// strLen := len(str)
|
||||
// for i := 0; i < charsPerFrame/strLen; i++ {
|
||||
// p.GlyphRend.DrawTextOpenGLAbs(str, gglm.NewVec3(xOff, float32(p.GlyphRend.Atlas.LineHeight)*5+yOff, 0), textColor)
|
||||
// }
|
||||
|
||||
// fmt.Println("FPS:", int(timing.GetAvgFPS()), "; Draws per frame:", charsPerFrame/16384)
|
||||
}
|
||||
|
||||
func (p *program) drawGrid() {
|
||||
|
||||
@ -29,7 +29,6 @@ void main()
|
||||
|
||||
v2fUV0 = aUV0 + aVertPos.xy * sizeUV;
|
||||
v2fColor = aVertColor;
|
||||
v2fFragPos = vec3(modelMat * vec4(aVertPos, 1.0));
|
||||
|
||||
gl_Position = projViewMat * modelMat * vec4(aVertPos, 1.0);
|
||||
}
|
||||
@ -37,9 +36,8 @@ void main()
|
||||
//shader:fragment
|
||||
#version 410
|
||||
|
||||
in vec4 v2fColor;
|
||||
in vec2 v2fUV0;
|
||||
in vec3 v2fFragPos;
|
||||
in vec4 v2fColor;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
@ -54,6 +52,6 @@ void main()
|
||||
// }
|
||||
// else
|
||||
{
|
||||
fragColor = vec4(v2fColor.rgb, texColor.r);
|
||||
fragColor = vec4(v2fColor.rgb, texColor.r*v2fColor.a);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user