This commit is contained in:
@@ -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 {
|
||||
|
||||
32
app/src/main/java/gui/AssetManager.java
Normal file
32
app/src/main/java/gui/AssetManager.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 399 KiB After Width: | Height: | Size: 399 KiB |
Reference in New Issue
Block a user