diff --git a/com/danitheskunk/skunkworks/BaseWindow.java b/com/danitheskunk/skunkworks/BaseWindow.java new file mode 100644 index 0000000..75e8e08 --- /dev/null +++ b/com/danitheskunk/skunkworks/BaseWindow.java @@ -0,0 +1,17 @@ +package com.danitheskunk.skunkworks; + +abstract class BaseWindow implements IWindow { + protected final Engine engine; + + BaseWindow(Engine engine) { + this.engine = engine; + } + + public IFont loadFontTileset(String path) { + var img = engine.loadImage(path); + var charSize = Vec2i.div(img.getSize(), 16); + var tex = loadTextureArray(img, charSize); + assert tex.size() == 256; + return new FontTileset(tex); + } +} diff --git a/com/danitheskunk/skunkworks/FontTileset.java b/com/danitheskunk/skunkworks/FontTileset.java new file mode 100644 index 0000000..419f51c --- /dev/null +++ b/com/danitheskunk/skunkworks/FontTileset.java @@ -0,0 +1,31 @@ +package com.danitheskunk.skunkworks; + +import java.util.List; + +class FontTileset implements IFont { + private List textures; + private Vec2i charSize; + + FontTileset(List textures) { + this.textures = textures; + this.charSize = textures.get(0).getSize(); + } + + @Override + public int getCharWidth(int ch) { + return charSize.getX(); + } + + @Override + public int getLineHeight(int ch) { + return charSize.getY(); + } + + @Override + public ITexture getTexture(int ch) { + if(ch >= 256 || ch < 0) { + ch = 0; + } + return textures.get(ch); + } +} diff --git a/com/danitheskunk/skunkworks/GLWindow.java b/com/danitheskunk/skunkworks/GLWindow.java index 9c4bbed..1228bd4 100644 --- a/com/danitheskunk/skunkworks/GLWindow.java +++ b/com/danitheskunk/skunkworks/GLWindow.java @@ -11,9 +11,8 @@ import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.system.MemoryUtil.NULL; -class GLWindow implements IWindow { +class GLWindow extends BaseWindow { private boolean debug; - private final Engine engine; private final GLRenderContext renderContext; private boolean shouldClose; private final Vec2i size; @@ -21,12 +20,12 @@ class GLWindow implements IWindow { private final long window; public GLWindow(Vec2i size, String title, Engine engine) { + super(engine); GLFWErrorCallback.createPrint(System.err).set(); if(!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints(); this.debug = false; - this.engine = engine; this.size = size; window = glfwCreateWindow(size.getX(), size.getY(), title, NULL, NULL); diff --git a/com/danitheskunk/skunkworks/IFont.java b/com/danitheskunk/skunkworks/IFont.java new file mode 100644 index 0000000..7803025 --- /dev/null +++ b/com/danitheskunk/skunkworks/IFont.java @@ -0,0 +1,7 @@ +package com.danitheskunk.skunkworks; + +public interface IFont { + int getCharWidth(int ch); + int getLineHeight(int ch); + ITexture getTexture(int ch); +} diff --git a/com/danitheskunk/skunkworks/IWindow.java b/com/danitheskunk/skunkworks/IWindow.java index 8da9faf..56fff5c 100644 --- a/com/danitheskunk/skunkworks/IWindow.java +++ b/com/danitheskunk/skunkworks/IWindow.java @@ -3,6 +3,7 @@ package com.danitheskunk.skunkworks; import java.util.List; public interface IWindow { + IFont loadFontTileset(String path); ITexture loadTexture(Image image); ITexture loadTexture(String path); List loadTextureArray(Image image, Vec2i tileSize);