diff options
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/lwjgl')
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java | 38 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java | 20 |
2 files changed, 56 insertions, 2 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java index 72cb75a..64fbe1f 100644 --- a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -8,14 +8,14 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.shader.Framebuffer; -import org.lwjgl.nanovg.NVGColor; -import org.lwjgl.nanovg.NVGPaint; +import org.lwjgl.nanovg.*; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.GL11; import java.awt.*; import java.util.function.LongConsumer; +import static org.lwjgl.nanovg.NanoSVG.NSVG_FLAGS_VISIBLE; import static org.lwjgl.nanovg.NanoVG.*; import static org.lwjgl.nanovg.NanoVGGL2.NVG_ANTIALIAS; import static org.lwjgl.nanovg.NanoVGGL2.nvgCreate; @@ -130,6 +130,40 @@ public final class RenderManager { } } + public static void drawSVGImage(long vg, String fileName, float x, float y, float width, float height) { + if (ImageLoader.INSTANCE.loadSVGImage(fileName)) { + NSVGImage image = ImageLoader.INSTANCE.getSVG(fileName); + NSVGShape shape; + NSVGPath path; + int i; + for(shape = image.shapes(); shape != null; shape.next()) { // throws npe + if (!(shape.flags() == NSVG_FLAGS_VISIBLE)) { + continue; + } + + nvgFillColor(vg, color(vg, shape.fill().color())); + nvgStrokeColor(vg, color(vg, shape.stroke().color())); + nvgStrokeWidth(vg, shape.strokeWidth()); + + for(path = shape.paths(); path != null; path.next()) { + nvgBeginPath(vg); + nvgMoveTo(vg, path.pts().get(0), path.pts().get(1)); + for(i = 0; i < path.npts() - 1; i += 3) { + float[] p = new float[100]; // INSta CRASH POGGERS + path.pts().get(p, i * 2, 100); + nvgBezierTo(vg, p[2], p[3], p[4], p[5], p[6], p[7]); + } //hello imma add the svg i got from wikipedia + if(path.closed() == 1) { + nvgLineTo(vg, path.pts().get(0), path.pts().get(1)); + } + nvgStroke(vg); + } + + + } + } + } + public static void drawLine(long vg, float x, float y, float endX, float endY, float width, int color) { nvgBeginPath(vg); nvgMoveTo(vg, x, y); diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java index b0cb6d4..4e07215 100644 --- a/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java +++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java @@ -1,6 +1,8 @@ package io.polyfrost.oneconfig.lwjgl.image; import io.polyfrost.oneconfig.lwjgl.IOUtil; +import org.lwjgl.nanovg.NSVGImage; +import org.lwjgl.nanovg.NanoSVG; import org.lwjgl.nanovg.NanoVG; import org.lwjgl.stb.STBImage; @@ -9,6 +11,7 @@ import java.util.HashMap; public class ImageLoader { private final HashMap<String, Image> imageHashMap = new HashMap<>(); + private final HashMap<String, NSVGImage> NSVGImageHashMap = new HashMap<>(); public static ImageLoader INSTANCE = new ImageLoader(); public boolean loadImage(long vg, String fileName) { @@ -33,7 +36,24 @@ public class ImageLoader { return true; } + public boolean loadSVGImage(String fileName) { + if(!NSVGImageHashMap.containsKey(fileName)) { + try { + NSVGImageHashMap.put(fileName, NanoSVG.nsvgParseFromFile(fileName, "px", 96f)); + } catch (Exception e) { // just in case + System.err.println("Failed to parse SVG file"); + return false; + } + return true; + } + return true; + } + public Image getImage(String fileName) { return imageHashMap.get(fileName); } + + public NSVGImage getSVG(String fileName) { + return NSVGImageHashMap.get(fileName); + } } |