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]; + } +}