Compare commits

..

No commits in common. "07ced1f4307692ae5f816c943a6f7c0289a55d52" and "7a792c2a46c6a25fcaaedbce7e4aee0c8fd5c93d" have entirely different histories.

10 changed files with 5 additions and 90 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -7,10 +7,9 @@ public class Test {
var img = engine.loadImage("C:\\Users\\dani\\Videos\\Screenshot 2022-06-25 17-00-59.png"); 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 tex2 = window.loadTexture("C:\\art\\pixel stuff.png");
var tileset = window.loadTextureArray("C:\\stream\\coding\\rlc\\tilemap.png", new Vec2i(16, 16)); 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); //img.drawImage(img2, Vec2i.ZERO);
var tex = window.loadTexture(img); var tex = window.loadTexture(img);
window.setDebug(false); window.setDebug(true);
while(!window.shouldClose()) { while(!window.shouldClose()) {
window.tick(); window.tick();
@ -28,8 +27,6 @@ public class Test {
new Recti(new Vec2i(400, 400), new Vec2i(16, 16)), new Recti(new Vec2i(400, 400), new Vec2i(16, 16)),
tileset.get(0x30) tileset.get(0x30)
); );
renderContext.drawString(new Vec2i(100, 100), "hello world mew", font);
window.renderFinish(renderContext); window.renderFinish(renderContext);
} }
} }

View File

@ -1,24 +0,0 @@
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);
}
}
}

View File

@ -1,17 +0,0 @@
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);
}
}

View File

@ -1,31 +0,0 @@
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);
}
}

View File

@ -2,7 +2,7 @@ package com.danitheskunk.skunkworks;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
class GLRenderContext extends BaseRenderContext implements IRenderContext{ class GLRenderContext implements IRenderContext{
private final GLTextureAtlas atlas; private final GLTextureAtlas atlas;
public GLRenderContext(GLTextureAtlas atlas) { public GLRenderContext(GLTextureAtlas atlas) {

View File

@ -11,8 +11,9 @@ 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 extends BaseWindow { class GLWindow implements IWindow {
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;
@ -20,12 +21,12 @@ class GLWindow extends BaseWindow {
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);
@ -41,8 +42,6 @@ class GLWindow extends BaseWindow {
glOrtho(0.0f, size.getX(), size.getY(), 0.0f, 0.0f, 1.0f); glOrtho(0.0f, size.getX(), size.getY(), 0.0f, 0.0f, 1.0f);
glEnable(GL_COLOR); glEnable(GL_COLOR);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
textureAtlas = new GLTextureAtlas(); textureAtlas = new GLTextureAtlas();
renderContext = new GLRenderContext(textureAtlas); renderContext = new GLRenderContext(textureAtlas);

View File

@ -1,7 +0,0 @@
package com.danitheskunk.skunkworks;
public interface IFont {
int getCharWidth(int ch);
int getLineHeight(int ch);
ITexture getTexture(int ch);
}

View File

@ -2,7 +2,6 @@ package com.danitheskunk.skunkworks;
public interface IRenderContext { public interface IRenderContext {
void drawRectangle(Recti rect, Color color); 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);
void drawTextureRectangle(Recti rect, ITexture texture, Color color); void drawTextureRectangle(Recti rect, ITexture texture, Color color);
} }

View File

@ -3,7 +3,6 @@ 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);