diff --git a/EGA8x14.png b/EGA8x14.png new file mode 100644 index 0000000..5da0d32 Binary files /dev/null and b/EGA8x14.png differ diff --git a/Test.java b/Test.java index ec78b78..e269725 100644 --- a/Test.java +++ b/Test.java @@ -7,9 +7,10 @@ public class Test { var img = engine.loadImage("C:\\Users\\dani\\Videos\\Screenshot 2022-06-25 17-00-59.png"); var tex2 = window.loadTexture("C:\\art\\pixel stuff.png"); var tileset = window.loadTextureArray("C:\\stream\\coding\\rlc\\tilemap.png", new Vec2i(16, 16)); + var font = window.loadFontTileset("EGA8x14.png"); //img.drawImage(img2, Vec2i.ZERO); var tex = window.loadTexture(img); - window.setDebug(true); + window.setDebug(false); while(!window.shouldClose()) { window.tick(); @@ -27,6 +28,8 @@ public class Test { new Recti(new Vec2i(400, 400), new Vec2i(16, 16)), tileset.get(0x30) ); + + renderContext.drawString(new Vec2i(100, 100), "hello world mew", font); window.renderFinish(renderContext); } } diff --git a/com/danitheskunk/skunkworks/BaseRenderContext.java b/com/danitheskunk/skunkworks/BaseRenderContext.java new file mode 100644 index 0000000..aff9d46 --- /dev/null +++ b/com/danitheskunk/skunkworks/BaseRenderContext.java @@ -0,0 +1,24 @@ +package com.danitheskunk.skunkworks; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +abstract class BaseRenderContext implements IRenderContext { + public void drawString(Vec2i pos, String string, IFont font) { + int x = pos.getX(); + int y = pos.getY(); + IntBuffer buf; + try { + buf = ByteBuffer.wrap(string.getBytes("UTF-32")).asIntBuffer(); + } catch(UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + for(int i = 0; i < string.length(); ++i) { + int ch = buf.get(i); + var tex = font.getTexture(ch); + drawTextureRectangle(new Recti(new Vec2i(x, y), tex.getSize()), tex); + x += font.getCharWidth(ch); + } + } +} diff --git a/com/danitheskunk/skunkworks/GLRenderContext.java b/com/danitheskunk/skunkworks/GLRenderContext.java index 88269ee..f3e5d30 100644 --- a/com/danitheskunk/skunkworks/GLRenderContext.java +++ b/com/danitheskunk/skunkworks/GLRenderContext.java @@ -2,7 +2,7 @@ package com.danitheskunk.skunkworks; import static org.lwjgl.opengl.GL11.*; -class GLRenderContext implements IRenderContext{ +class GLRenderContext extends BaseRenderContext implements IRenderContext{ private final GLTextureAtlas atlas; public GLRenderContext(GLTextureAtlas atlas) { diff --git a/com/danitheskunk/skunkworks/GLWindow.java b/com/danitheskunk/skunkworks/GLWindow.java index 1228bd4..5bdc803 100644 --- a/com/danitheskunk/skunkworks/GLWindow.java +++ b/com/danitheskunk/skunkworks/GLWindow.java @@ -41,6 +41,8 @@ class GLWindow extends BaseWindow { glOrtho(0.0f, size.getX(), size.getY(), 0.0f, 0.0f, 1.0f); glEnable(GL_COLOR); glEnable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); textureAtlas = new GLTextureAtlas(); renderContext = new GLRenderContext(textureAtlas); diff --git a/com/danitheskunk/skunkworks/IRenderContext.java b/com/danitheskunk/skunkworks/IRenderContext.java index 3aede41..93a7286 100644 --- a/com/danitheskunk/skunkworks/IRenderContext.java +++ b/com/danitheskunk/skunkworks/IRenderContext.java @@ -2,6 +2,7 @@ package com.danitheskunk.skunkworks; public interface IRenderContext { void drawRectangle(Recti rect, Color color); + void drawString(Vec2i pos, String string, IFont font); void drawTextureRectangle(Recti rect, ITexture texture); void drawTextureRectangle(Recti rect, ITexture texture, Color color); }