From a4b7dfd39569d47d9cc31e2476ba0d7900663f38 Mon Sep 17 00:00:00 2001 From: bloeys Date: Sun, 3 Jul 2022 09:22:51 +0400 Subject: [PATCH] Update texture atlas straight from memory --- glyphs/font_atlas.go | 4 ++-- glyphs/glyphs.go | 18 +++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/glyphs/font_atlas.go b/glyphs/font_atlas.go index 85c6999..4668780 100755 --- a/glyphs/font_atlas.go +++ b/glyphs/font_atlas.go @@ -67,8 +67,8 @@ func NewFontAtlasFromFont(f *truetype.Font, face font.Face, pointSize uint) (*Fo assert.T(len(glyphs) > 0, "no glyphs") //Choose atlas size - atlasSizeX := 512 - atlasSizeY := 512 + atlasSizeX := 64 + atlasSizeY := 64 const charPaddingX = 2 const charPaddingY = 2 diff --git a/glyphs/glyphs.go b/glyphs/glyphs.go index 97e48db..8ca39f8 100755 --- a/glyphs/glyphs.go +++ b/glyphs/glyphs.go @@ -3,7 +3,6 @@ package glyphs import ( "errors" "math" - "os" "github.com/bloeys/gglm/gglm" "github.com/bloeys/nmage/assets" @@ -140,7 +139,7 @@ func (gr *GlyphRend) SetFace(fontOptions *truetype.Options) error { } gr.Atlas = newAtlas - gr.updateFontAtlasTexture("temp-atlas") + gr.updateFontAtlasTexture() return nil } @@ -152,7 +151,7 @@ func (gr *GlyphRend) SetFontFromFile(fontFile string, fontOptions *truetype.Opti } gr.Atlas = atlas - gr.updateFontAtlasTexture(fontFile) + gr.updateFontAtlasTexture() return nil } @@ -160,20 +159,13 @@ func (gr *GlyphRend) SetFontFromFile(fontFile string, fontOptions *truetype.Opti //and updates the GlyphRend.AtlasTex field. // //Any old textures are deleted -func (gr *GlyphRend) updateFontAtlasTexture(fontFile string) error { +func (gr *GlyphRend) updateFontAtlasTexture() error { if gr.AtlasTex != nil { gl.DeleteTextures(1, &gr.AtlasTex.TexID) } - pngFileName := fontFile + "-atlas.png" - err := SaveImgToPNG(gr.Atlas.Img, pngFileName) - if err != nil { - return err - } - defer os.Remove(pngFileName) - - atlasTex, err := assets.LoadTexturePNG(pngFileName, nil) + atlasTex, err := assets.LoadTextureInMemImg(gr.Atlas.Img, nil) if err != nil { return err } @@ -216,7 +208,7 @@ func NewGlyphRend(fontFile string, fontOptions *truetype.Options, screenWidth, s } gr.Atlas = atlas - err = gr.updateFontAtlasTexture(fontFile) + err = gr.updateFontAtlasTexture() if err != nil { return nil, err }