From 7f8b3e8786fc168aa7a9e9540db8d466ac06a442 Mon Sep 17 00:00:00 2001 From: Speiger Date: Sat, 20 Jul 2024 20:11:06 +0200 Subject: [PATCH] Start on true type fonts --- .../rendering/gui/font/FontTexture.java | 1 + .../font/providers/STBTrueTypeProvider.java | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/main/java/speiger/src/coreengine/rendering/gui/font/providers/STBTrueTypeProvider.java diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/FontTexture.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/FontTexture.java index fc1eef9..7c47de5 100644 --- a/src/main/java/speiger/src/coreengine/rendering/gui/font/FontTexture.java +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/FontTexture.java @@ -19,6 +19,7 @@ public class FontTexture extends BaseTexture { @Override public void load(IAssetProvider provider) { + //TODO use old texture system instead GL45.glTextureStorage2D(id, 1, GLTextureFormat.RGBA.glValue(), bounds, bounds); } diff --git a/src/main/java/speiger/src/coreengine/rendering/gui/font/providers/STBTrueTypeProvider.java b/src/main/java/speiger/src/coreengine/rendering/gui/font/providers/STBTrueTypeProvider.java new file mode 100644 index 0000000..cc66512 --- /dev/null +++ b/src/main/java/speiger/src/coreengine/rendering/gui/font/providers/STBTrueTypeProvider.java @@ -0,0 +1,42 @@ +package speiger.src.coreengine.rendering.gui.font.providers; + +import org.lwjgl.stb.STBTTFontinfo; +import org.lwjgl.stb.STBTruetype; + +import speiger.src.collections.ints.sets.IntSet; +import speiger.src.coreengine.rendering.gui.font.glyth.GlythData; + +public class STBTrueTypeProvider implements IFontProvider { + long data; + STBTTFontinfo info; + IntSet skip; + float oversample; + float xOff; + float yOff; + float pointScale; + float ascent; + + public STBTrueTypeProvider(long data, STBTTFontinfo info, float size, float oversample, float xOff, float yOff, String skip) { + this.data = data; + this.info = info; + skip.codePoints().forEach(this.skip::add); + this.oversample = oversample; + this.xOff = xOff; + this.yOff = yOff; + pointScale = STBTruetype.stbtt_ScaleForPixelHeight(info, size * oversample); + int[] ascent = new int[1]; + STBTruetype.stbtt_GetFontVMetrics(info, ascent, new int[1], new int[1]); + this.ascent = pointScale * ascent[0]; + } + + @Override + public GlythData glythData(int codepoint) { + return null; + } + + @Override + public void close() { + + } + +}