aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java
blob: 0ec2b871b3ce0db1934929f5f993890d1c5fd2fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package io.polyfrost.oneconfig.lwjgl.font;

import io.polyfrost.oneconfig.lwjgl.IOUtil;

import java.io.IOException;
import java.nio.ByteBuffer;

import static org.lwjgl.nanovg.NanoVG.nvgCreateFontMem;

public class FontManager {
    public static FontManager INSTANCE = new FontManager();

    public void initialize(long vg) {
        for (Fonts fonts : Fonts.values()) {
            Font font = fonts.font;
            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);
            }
        }
    }
}