From c82fd6aac7dc78fbdd0075937cf8bf8c80b265bb Mon Sep 17 00:00:00 2001 From: bloeys Date: Mon, 4 Jul 2022 01:56:47 +0400 Subject: [PATCH] Correct alpha handling in glyph shader --- main.go | 27 ++++++++++++--------------- res/shaders/glyph.glsl | 6 ++---- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index e30d0f1..5451f39 100755 --- a/main.go +++ b/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() { diff --git a/res/shaders/glyph.glsl b/res/shaders/glyph.glsl index a3823f1..17bc197 100755 --- a/res/shaders/glyph.glsl +++ b/res/shaders/glyph.glsl @@ -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); } }