Fixes #5
All checks were successful
Linux arm64 / Build (push) Successful in 41s

This commit is contained in:
2025-02-02 11:33:21 +01:00
parent d806420d21
commit 990c830590
10 changed files with 50 additions and 10 deletions

View File

@@ -28,7 +28,9 @@ dependencies {
implementation "org.lwjgl:lwjgl-stb:3.3.4" implementation "org.lwjgl:lwjgl-stb:3.3.4"
runtimeOnly "org.lwjgl:lwjgl-stb::natives-$os" implementation "org.lwjgl:lwjgl-stb::natives-linux"
implementation "org.lwjgl:lwjgl-stb::natives-windows"
implementation "org.lwjgl:lwjgl-stb::natives-macos"
} }
application { application {

View File

@@ -0,0 +1,32 @@
package gui;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class AssetManager {
public static byte[] getResource(String name) {
// we first search it in files
File f = new File(name);
if (f.exists()){
FileInputStream fis;
try {
fis = new FileInputStream(f);
return fis.readAllBytes();
} catch (IOException e) {
e.printStackTrace();
}
}
// then in the jar
InputStream is = ClassLoader.getSystemResourceAsStream(name);
try {
return is.readAllBytes();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -1,5 +1,6 @@
package gui.constants; package gui.constants;
import gui.AssetManager;
import imgui.ImFont; import imgui.ImFont;
import imgui.ImFontConfig; import imgui.ImFontConfig;
import imgui.ImFontGlyphRangesBuilder; import imgui.ImFontGlyphRangesBuilder;
@@ -20,15 +21,15 @@ public class Fonts {
ImFontGlyphRangesBuilder builder = new ImFontGlyphRangesBuilder(); ImFontGlyphRangesBuilder builder = new ImFontGlyphRangesBuilder();
builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesDefault()); builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesDefault());
builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesCyrillic()); builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesCyrillic());
// builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesChineseFull());
ImFontConfig cfg = new ImFontConfig(); ImFontConfig cfg = new ImFontConfig();
cfg.setGlyphRanges(builder.buildRanges()); cfg.setGlyphRanges(builder.buildRanges());
COMIC = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "comic.ttf", 50.0f); COMIC = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("comic.ttf"), 50.0f);
ARIAL_BOLD = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "arial_bold.ttf", 50.0f); ARIAL_BOLD = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("arial_bold.ttf"), 50.0f);
ARIAL = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "arial.ttf", 50.0f, cfg); ARIAL = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("arial.ttf"), 50.0f, cfg);
CHERI = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "cheri.ttf", 50.0f); CHERI = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("cheri.ttf"), 50.0f);
INFECTED = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "INFECTED.ttf", 50.0f); INFECTED = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("INFECTED.ttf"), 50.0f);
} }
} }

View File

@@ -5,16 +5,21 @@ import java.nio.ByteBuffer;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.lwjgl.stb.STBImage; import org.lwjgl.stb.STBImage;
import gui.AssetManager;
public class Images { public class Images {
public static int BACKGROUND; public static int BACKGROUND;
private static int loadTexture(String fileName) { private static int loadTexture(byte[] imageData) {
int[] width = new int[1]; int[] width = new int[1];
int[] height = new int[1]; int[] height = new int[1];
int[] channelCount = new int[1]; int[] channelCount = new int[1];
ByteBuffer pixels = STBImage.stbi_load(fileName, width, height, channelCount, 4); ByteBuffer img = ByteBuffer.allocateDirect(imageData.length);
img.put(imageData);
img.flip();
ByteBuffer pixels = STBImage.stbi_load_from_memory(img, width, height, channelCount, 4);
int textureID = GL11.glGenTextures(); int textureID = GL11.glGenTextures();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
@@ -33,7 +38,7 @@ public class Images {
} }
public static void reloadImages() { public static void reloadImages() {
BACKGROUND = loadTexture(Options.BackgroundPath); BACKGROUND = loadTexture(AssetManager.getResource(Options.BackgroundPath));
} }
} }

View File

Before

Width:  |  Height:  |  Size: 399 KiB

After

Width:  |  Height:  |  Size: 399 KiB