diff --git a/app/build.gradle b/app/build.gradle index 0067423..d3bbcea 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,7 +28,9 @@ dependencies { 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 { diff --git a/app/src/main/java/gui/AssetManager.java b/app/src/main/java/gui/AssetManager.java new file mode 100644 index 0000000..9cc8d96 --- /dev/null +++ b/app/src/main/java/gui/AssetManager.java @@ -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; + } + +} diff --git a/app/src/main/java/gui/constants/Fonts.java b/app/src/main/java/gui/constants/Fonts.java index af00876..e1eaf4f 100644 --- a/app/src/main/java/gui/constants/Fonts.java +++ b/app/src/main/java/gui/constants/Fonts.java @@ -1,5 +1,6 @@ package gui.constants; +import gui.AssetManager; import imgui.ImFont; import imgui.ImFontConfig; import imgui.ImFontGlyphRangesBuilder; @@ -20,15 +21,15 @@ public class Fonts { ImFontGlyphRangesBuilder builder = new ImFontGlyphRangesBuilder(); builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesDefault()); builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesCyrillic()); - // builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesChineseFull()); + ImFontConfig cfg = new ImFontConfig(); cfg.setGlyphRanges(builder.buildRanges()); - COMIC = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "comic.ttf", 50.0f); - ARIAL_BOLD = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "arial_bold.ttf", 50.0f); - ARIAL = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "arial.ttf", 50.0f, cfg); - CHERI = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "cheri.ttf", 50.0f); - INFECTED = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "INFECTED.ttf", 50.0f); + COMIC = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("comic.ttf"), 50.0f); + ARIAL_BOLD = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("arial_bold.ttf"), 50.0f); + ARIAL = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("arial.ttf"), 50.0f, cfg); + CHERI = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("cheri.ttf"), 50.0f); + INFECTED = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("INFECTED.ttf"), 50.0f); } } diff --git a/app/src/main/java/gui/constants/Images.java b/app/src/main/java/gui/constants/Images.java index 7421c32..35c40f9 100644 --- a/app/src/main/java/gui/constants/Images.java +++ b/app/src/main/java/gui/constants/Images.java @@ -5,16 +5,21 @@ import java.nio.ByteBuffer; import org.lwjgl.opengl.GL11; import org.lwjgl.stb.STBImage; +import gui.AssetManager; + public class Images { public static int BACKGROUND; - private static int loadTexture(String fileName) { + private static int loadTexture(byte[] imageData) { int[] width = new int[1]; int[] height = 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(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); @@ -33,7 +38,7 @@ public class Images { } public static void reloadImages() { - BACKGROUND = loadTexture(Options.BackgroundPath); + BACKGROUND = loadTexture(AssetManager.getResource(Options.BackgroundPath)); } } diff --git a/app/INFECTED.ttf b/app/src/main/resources/INFECTED.ttf similarity index 100% rename from app/INFECTED.ttf rename to app/src/main/resources/INFECTED.ttf diff --git a/app/arial.ttf b/app/src/main/resources/arial.ttf similarity index 100% rename from app/arial.ttf rename to app/src/main/resources/arial.ttf diff --git a/app/arial_bold.ttf b/app/src/main/resources/arial_bold.ttf similarity index 100% rename from app/arial_bold.ttf rename to app/src/main/resources/arial_bold.ttf diff --git a/app/background.png b/app/src/main/resources/background.png similarity index 100% rename from app/background.png rename to app/src/main/resources/background.png diff --git a/app/cheri.ttf b/app/src/main/resources/cheri.ttf similarity index 100% rename from app/cheri.ttf rename to app/src/main/resources/cheri.ttf diff --git a/app/comic.ttf b/app/src/main/resources/comic.ttf similarity index 100% rename from app/comic.ttf rename to app/src/main/resources/comic.ttf