added image loading

This commit is contained in:
Dani The Skunk 2022-09-14 05:45:15 +02:00
parent 77ef6a6e56
commit d43771a4e6
2 changed files with 49 additions and 0 deletions

View File

@ -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);
};
}
}

View File

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