implemented loadTextureArray (for tilesets)
This commit is contained in:
parent
829a017d2e
commit
1316ee560b
|
@ -1,4 +1,5 @@
|
||||||
import com.danitheskunk.skunkworks.*;
|
import com.danitheskunk.skunkworks.*;
|
||||||
|
import org.w3c.dom.css.Rect;
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -7,6 +8,7 @@ public class Test {
|
||||||
var img2 = engine.loadImage("C:\\art\\pixel stuff.png");
|
var img2 = engine.loadImage("C:\\art\\pixel stuff.png");
|
||||||
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));
|
||||||
//img.drawImage(img2, Vec2i.ZERO);
|
//img.drawImage(img2, Vec2i.ZERO);
|
||||||
var tex = window.loadTexture(img);
|
var tex = window.loadTexture(img);
|
||||||
|
|
||||||
|
@ -25,6 +27,11 @@ public class Test {
|
||||||
new Recti(new Vec2i(200, 100), tex2.getSize()),
|
new Recti(new Vec2i(200, 100), tex2.getSize()),
|
||||||
tex2
|
tex2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
renderContext.drawTextureRectangle(
|
||||||
|
new Recti(new Vec2i(400, 400), new Vec2i(16, 16)),
|
||||||
|
tileset.get(0x30)
|
||||||
|
);
|
||||||
window.renderFinish(renderContext);
|
window.renderFinish(renderContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ import org.lwjgl.opengl.GL;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import org.lwjgl.stb.STBRectPack;
|
import org.lwjgl.stb.STBRectPack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
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;
|
||||||
|
@ -59,6 +62,28 @@ public class GLWindow implements IWindow {
|
||||||
return textureAtlas.addTexture(img);
|
return textureAtlas.addTexture(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ITexture> loadTextureArray(Image image, Vec2i tileSize) {
|
||||||
|
var tileCount = Vec2i.div(image.getSize(), tileSize);
|
||||||
|
var tiles = new ArrayList<ITexture>();
|
||||||
|
|
||||||
|
for(int y = 0; y < tileCount.getY(); ++y) {
|
||||||
|
for(int x = 0; x < tileCount.getX(); ++x) {
|
||||||
|
var rect = new Recti(Vec2i.mul(new Vec2i(x, y), tileSize), tileSize);
|
||||||
|
var img = image.getSubImage(rect);
|
||||||
|
tiles.add(loadTexture(img));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ITexture> loadTextureArray(String path, Vec2i tileSize) {
|
||||||
|
var img = engine.loadImage(path);
|
||||||
|
return loadTextureArray(img, tileSize);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderFinish(IRenderContext context) {
|
public void renderFinish(IRenderContext context) {
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package com.danitheskunk.skunkworks;
|
package com.danitheskunk.skunkworks;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface IWindow {
|
public interface IWindow {
|
||||||
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(String path, Vec2i tileSize);
|
||||||
void renderFinish(IRenderContext context);
|
void renderFinish(IRenderContext context);
|
||||||
IRenderContext renderStart();
|
IRenderContext renderStart();
|
||||||
boolean shouldClose();
|
boolean shouldClose();
|
||||||
|
|
Loading…
Reference in New Issue