diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-04-16 14:51:58 +0900 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-04-16 14:51:58 +0900 |
commit | cf164be0c8f43c3d1387c9c9f7ae73c2cf1b3a02 (patch) | |
tree | c3f2cbfe39919941b9bb04f6de2e3cec103509fd /src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java | |
parent | f10f1165a7c2ea88ce7bb265d51b52eeaa64d8f8 (diff) | |
download | OneConfig-cf164be0c8f43c3d1387c9c9f7ae73c2cf1b3a02.tar.gz OneConfig-cf164be0c8f43c3d1387c9c9f7ae73c2cf1b3a02.tar.bz2 OneConfig-cf164be0c8f43c3d1387c9c9f7ae73c2cf1b3a02.zip |
merge rendering files + remove themes
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java')
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java new file mode 100644 index 0000000..20a8cc7 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java @@ -0,0 +1,34 @@ +package io.polyfrost.oneconfig.lwjgl.font; + +import io.polyfrost.oneconfig.lwjgl.IOUtil; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; + +import static org.lwjgl.nanovg.NanoVG.nvgCreateFontMem; + +public class FontManager { + public static FontManager INSTANCE = new FontManager(); + private final ArrayList<Font> fonts = new ArrayList<>(); + + public void initialize(long vg) { + fonts.add(new Font("inter-bold", "/assets/oneconfig/font/Inter-Bold.ttf")); + fonts.add(new Font("mc-regular", "/assets/oneconfig/font/Minecraft-Regular.otf")); + for (Font font : fonts) { + int loaded = -1; + try { + ByteBuffer buffer = IOUtil.resourceToByteBuffer(font.getFileName()); + loaded = nvgCreateFontMem(vg, font.getName(), buffer, 0); + font.setBuffer(buffer); + } catch (IOException e) { + e.printStackTrace(); + } + if (loaded == -1) { + throw new RuntimeException("Failed to initialize font " + font.getName()); + } else { + font.setLoaded(true); + } + } + } +} |