implemented FontTileset
This commit is contained in:
parent
7a792c2a46
commit
3edbc36844
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.danitheskunk.skunkworks;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class FontTileset implements IFont {
|
||||||
|
private List<ITexture> textures;
|
||||||
|
private Vec2i charSize;
|
||||||
|
|
||||||
|
FontTileset(List<ITexture> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,9 +11,8 @@ import static org.lwjgl.glfw.GLFW.*;
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import static org.lwjgl.system.MemoryUtil.NULL;
|
import static org.lwjgl.system.MemoryUtil.NULL;
|
||||||
|
|
||||||
class GLWindow implements IWindow {
|
class GLWindow extends BaseWindow {
|
||||||
private boolean debug;
|
private boolean debug;
|
||||||
private final Engine engine;
|
|
||||||
private final GLRenderContext renderContext;
|
private final GLRenderContext renderContext;
|
||||||
private boolean shouldClose;
|
private boolean shouldClose;
|
||||||
private final Vec2i size;
|
private final Vec2i size;
|
||||||
|
@ -21,12 +20,12 @@ class GLWindow implements IWindow {
|
||||||
private final long window;
|
private final long window;
|
||||||
|
|
||||||
public GLWindow(Vec2i size, String title, Engine engine) {
|
public GLWindow(Vec2i size, String title, Engine engine) {
|
||||||
|
super(engine);
|
||||||
GLFWErrorCallback.createPrint(System.err).set();
|
GLFWErrorCallback.createPrint(System.err).set();
|
||||||
if(!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW");
|
if(!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW");
|
||||||
|
|
||||||
glfwDefaultWindowHints();
|
glfwDefaultWindowHints();
|
||||||
this.debug = false;
|
this.debug = false;
|
||||||
this.engine = engine;
|
|
||||||
this.size = size;
|
this.size = size;
|
||||||
|
|
||||||
window = glfwCreateWindow(size.getX(), size.getY(), title, NULL, NULL);
|
window = glfwCreateWindow(size.getX(), size.getY(), title, NULL, NULL);
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.danitheskunk.skunkworks;
|
||||||
|
|
||||||
|
public interface IFont {
|
||||||
|
int getCharWidth(int ch);
|
||||||
|
int getLineHeight(int ch);
|
||||||
|
ITexture getTexture(int ch);
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package com.danitheskunk.skunkworks;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface IWindow {
|
public interface IWindow {
|
||||||
|
IFont loadFontTileset(String path);
|
||||||
ITexture loadTexture(Image image);
|
ITexture loadTexture(Image image);
|
||||||
ITexture loadTexture(String path);
|
ITexture loadTexture(String path);
|
||||||
List<ITexture> loadTextureArray(Image image, Vec2i tileSize);
|
List<ITexture> loadTextureArray(Image image, Vec2i tileSize);
|
||||||
|
|
Loading…
Reference in New Issue