From d43771a4e6a0dd7a878d7afec98c63db026c7ff4 Mon Sep 17 00:00:00 2001 From: Dani The Skunk Date: Wed, 14 Sep 2022 05:45:15 +0200 Subject: [PATCH] added image loading --- com/danitheskunk/skunkworks/Engine.java | 32 +++++++++++++++++++++++++ com/danitheskunk/skunkworks/Image.java | 17 +++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 com/danitheskunk/skunkworks/Engine.java create mode 100644 com/danitheskunk/skunkworks/Image.java diff --git a/com/danitheskunk/skunkworks/Engine.java b/com/danitheskunk/skunkworks/Engine.java new file mode 100644 index 0000000..d0f761e --- /dev/null +++ b/com/danitheskunk/skunkworks/Engine.java @@ -0,0 +1,32 @@ +package com.danitheskunk.skunkworks; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.ByteBuffer; + +import static com.danitheskunk.skunkworks.GraphicsBackend.*; + +public class Engine { + public Image loadImage(String path) { + ByteBuffer buf; + try(FileInputStream fis = new FileInputStream(path)) { + buf = ByteBuffer.wrap(fis.readAllBytes()); + } catch(FileNotFoundException e) { + throw new RuntimeException(e); + } catch(IOException e) { + throw new RuntimeException(e); + } + return new Image(buf); + } + + public IWindow openWindow(int width, int height, String title) { + return openWindow(width, height, title, OPENGL); + } + + public IWindow openWindow(int width, int height, String title, GraphicsBackend graphicsBackend) { + return switch(graphicsBackend) { + case OPENGL -> new GLWindow(width, height, title); + }; + } +} diff --git a/com/danitheskunk/skunkworks/Image.java b/com/danitheskunk/skunkworks/Image.java new file mode 100644 index 0000000..4c2ab7b --- /dev/null +++ b/com/danitheskunk/skunkworks/Image.java @@ -0,0 +1,17 @@ +package com.danitheskunk.skunkworks; + +import org.lwjgl.stb.STBImage; + +import java.nio.ByteBuffer; + +public class Image { + ByteBuffer data; + int width, height; + Image(ByteBuffer buffer) { + //todo: resorce system + int[] x = {0}, y = {0}, n = {0}; + data = STBImage.stbi_load(buffer, x, y, n, 4); + width = x[0]; + height = y[0]; + } +}