renamed Image to Image32 to prepare to add Image8
This commit is contained in:
parent
fb3a988375
commit
4747abe678
|
@ -1,6 +1,6 @@
|
|||
package com.danitheskunk.skunkworks;
|
||||
|
||||
import com.danitheskunk.skunkworks.gfx.Image;
|
||||
import com.danitheskunk.skunkworks.gfx.Image32;
|
||||
import com.danitheskunk.skunkworks.gfx.NineSlice;
|
||||
import com.danitheskunk.skunkworks.gfx.font.FontTTF;
|
||||
import com.danitheskunk.skunkworks.gfx.font.FontTileset;
|
||||
|
@ -41,7 +41,7 @@ abstract public class BaseWindow implements IWindow {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NineSlice loadNineSlice(Image image) {
|
||||
public NineSlice loadNineSlice(Image32 image) {
|
||||
int x1 = -1;
|
||||
int x2 = -1;
|
||||
int y1 = -1;
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.danitheskunk.skunkworks;
|
|||
|
||||
import com.danitheskunk.skunkworks.backends.gl.Window;
|
||||
import com.danitheskunk.skunkworks.gfx.GraphicsBackend;
|
||||
import com.danitheskunk.skunkworks.gfx.Image;
|
||||
import com.danitheskunk.skunkworks.gfx.Image32;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
@ -65,8 +65,8 @@ public class Engine {
|
|||
return data;
|
||||
}
|
||||
|
||||
public Image loadImage(String path) {
|
||||
return new Image(loadBytes(path));
|
||||
public Image32 loadImage(String path) {
|
||||
return new Image32(loadBytes(path));
|
||||
}
|
||||
|
||||
public IWindow openWindow(Vec2i size, String title) {
|
||||
|
|
|
@ -23,15 +23,15 @@ public interface IWindow {
|
|||
|
||||
IFont loadFontTileset(String path);
|
||||
|
||||
NineSlice loadNineSlice(Image image);
|
||||
NineSlice loadNineSlice(Image32 image);
|
||||
|
||||
NineSlice loadNineSlice(String path);
|
||||
|
||||
ITexture loadTexture(Image image);
|
||||
ITexture loadTexture(Image32 image);
|
||||
|
||||
ITexture loadTexture(String path);
|
||||
|
||||
List<ITexture> loadTextureArray(Image image, Vec2i tileSize);
|
||||
List<ITexture> loadTextureArray(Image32 image, Vec2i tileSize);
|
||||
|
||||
List<ITexture> loadTextureArray(String path, Vec2i tileSize);
|
||||
|
||||
|
|
|
@ -2,15 +2,10 @@ package com.danitheskunk.skunkworks;
|
|||
|
||||
import com.danitheskunk.skunkworks.gfx.Color;
|
||||
import com.danitheskunk.skunkworks.gfx.IRenderContext;
|
||||
import com.danitheskunk.skunkworks.gfx.ITexture;
|
||||
import com.danitheskunk.skunkworks.gfx.Image;
|
||||
import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D;
|
||||
import com.danitheskunk.skunkworks.gfx.threedee.Mesh;
|
||||
import com.danitheskunk.skunkworks.gfx.threedee.Model;
|
||||
import org.lwjgl.assimp.*;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public class Test3D extends BaseGame {
|
||||
int trans;
|
||||
|
|
|
@ -3,13 +3,13 @@ package com.danitheskunk.skunkworks.backends.gl;
|
|||
import com.danitheskunk.skunkworks.Recti;
|
||||
import com.danitheskunk.skunkworks.Vec2i;
|
||||
import com.danitheskunk.skunkworks.gfx.ITexture;
|
||||
import com.danitheskunk.skunkworks.gfx.Image;
|
||||
import com.danitheskunk.skunkworks.gfx.Image32;
|
||||
|
||||
class Texture implements ITexture {
|
||||
private final Image img; //for re-blitting onto texture atlas
|
||||
private final Image32 img; //for re-blitting onto texture atlas
|
||||
private Recti texArea;
|
||||
|
||||
Texture(Recti texArea, Image img) {
|
||||
Texture(Recti texArea, Image32 img) {
|
||||
this.texArea = texArea;
|
||||
this.img = img;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class Texture implements ITexture {
|
|||
}
|
||||
|
||||
//setters
|
||||
Image getImg() {
|
||||
Image32 getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.danitheskunk.skunkworks.backends.gl;
|
|||
import com.danitheskunk.skunkworks.Recti;
|
||||
import com.danitheskunk.skunkworks.Vec2i;
|
||||
import com.danitheskunk.skunkworks.gfx.ITexture;
|
||||
import com.danitheskunk.skunkworks.gfx.Image;
|
||||
import com.danitheskunk.skunkworks.gfx.Image32;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -16,11 +16,11 @@ class TextureAtlas {
|
|||
final private int textureID;
|
||||
private final List<Texture> textures;
|
||||
private Texture atlasTexture; //for debugging
|
||||
private Image img;
|
||||
private Image32 img;
|
||||
private boolean shouldUpdate;
|
||||
|
||||
TextureAtlas() {
|
||||
img = new Image(new Vec2i(32, 32));
|
||||
img = new Image32(new Vec2i(32, 32));
|
||||
textureID = glGenTextures();
|
||||
textures = new ArrayList<>();
|
||||
shouldUpdate = true;
|
||||
|
@ -33,7 +33,7 @@ class TextureAtlas {
|
|||
|
||||
}
|
||||
|
||||
ITexture addTexture(Image img) {
|
||||
ITexture addTexture(Image32 img) {
|
||||
//todo: do the actual texture stuff
|
||||
//this.img = img;
|
||||
var texture = new Texture(new Recti(new Vec2i(0, 0), img.getSize()),
|
||||
|
@ -49,7 +49,7 @@ class TextureAtlas {
|
|||
}
|
||||
|
||||
void doubleAtlasSize() {
|
||||
img = new Image(Vec2i.mul(img.getSize(), 2));
|
||||
img = new Image32(Vec2i.mul(img.getSize(), 2));
|
||||
System.out.printf("Resized atlas to %dx%d\n",
|
||||
img.getSize().getX(),
|
||||
img.getSize().getY()
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.danitheskunk.skunkworks.backends.gl;
|
|||
import com.danitheskunk.skunkworks.*;
|
||||
import com.danitheskunk.skunkworks.gfx.IPipeline;
|
||||
import com.danitheskunk.skunkworks.gfx.ITexture;
|
||||
import com.danitheskunk.skunkworks.gfx.Image;
|
||||
import com.danitheskunk.skunkworks.gfx.Image32;
|
||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
@ -111,7 +111,7 @@ public class Window extends BaseWindow {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ITexture loadTexture(Image image) {
|
||||
public ITexture loadTexture(Image32 image) {
|
||||
return textureAtlas.addTexture(image);
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class Window extends BaseWindow {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ITexture> loadTextureArray(Image image, Vec2i tileSize) {
|
||||
public List<ITexture> loadTextureArray(Image32 image, Vec2i tileSize) {
|
||||
var tileCount = Vec2i.div(image.getSize(), tileSize);
|
||||
var tiles = new ArrayList<ITexture>();
|
||||
|
||||
|
|
|
@ -6,12 +6,12 @@ import org.lwjgl.stb.STBImage;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class Image {
|
||||
public class Image32 {
|
||||
private final byte[] data;
|
||||
private final Vec2i size;
|
||||
|
||||
//constructors
|
||||
public Image(ByteBuffer buffer) { //png or similar
|
||||
public Image32(ByteBuffer buffer) { //png or similar
|
||||
//todo: resource system
|
||||
int[] x = {0}, y = {0}, n = {0};
|
||||
var img = STBImage.stbi_load_from_memory(buffer, x, y, n, 4);
|
||||
|
@ -21,23 +21,23 @@ public class Image {
|
|||
img.get(data);
|
||||
}
|
||||
|
||||
public Image(Vec2i size) {
|
||||
public Image32(Vec2i size) {
|
||||
this.size = size;
|
||||
data = new byte[size.getX() * size.getY() * 4];
|
||||
}
|
||||
|
||||
public Image(ByteBuffer buffer, Vec2i size) {
|
||||
public Image32(ByteBuffer buffer, Vec2i size) {
|
||||
data = new byte[buffer.remaining()];
|
||||
buffer.get(data);
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void drawImage(Image srcImage, Vec2i destPos) {
|
||||
public void drawImage(Image32 srcImage, Vec2i destPos) {
|
||||
drawImage(srcImage, destPos, new Recti(Vec2i.ZERO,
|
||||
srcImage.getSize()));
|
||||
}
|
||||
|
||||
public void drawImage(Image srcImage, Vec2i destPos, Recti srcRect) {
|
||||
public void drawImage(Image32 srcImage, Vec2i destPos, Recti srcRect) {
|
||||
//todo: check bounds
|
||||
//todo: write in faster way than pixel stuff
|
||||
for(int y = 0; y < srcRect.getHeight(); ++y) {
|
||||
|
@ -72,8 +72,8 @@ public class Image {
|
|||
return size;
|
||||
}
|
||||
|
||||
public Image getSubImage(Recti rect) {
|
||||
Image img = new Image(rect.getSize());
|
||||
public Image32 getSubImage(Recti rect) {
|
||||
Image32 img = new Image32(rect.getSize());
|
||||
img.drawImage(this, Vec2i.ZERO, rect);
|
||||
return img;
|
||||
}
|
|
@ -3,7 +3,7 @@ package com.danitheskunk.skunkworks.gfx.font;
|
|||
import com.danitheskunk.skunkworks.IWindow;
|
||||
import com.danitheskunk.skunkworks.Vec2i;
|
||||
import com.danitheskunk.skunkworks.gfx.ITexture;
|
||||
import com.danitheskunk.skunkworks.gfx.Image;
|
||||
import com.danitheskunk.skunkworks.gfx.Image32;
|
||||
import org.lwjgl.stb.STBTTFontinfo;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -72,11 +72,11 @@ public class FontTTF extends BaseFont {
|
|||
buf.put(b);
|
||||
}
|
||||
buf.flip();
|
||||
tex = window.loadTexture(new Image(buf,
|
||||
tex = window.loadTexture(new Image32(buf,
|
||||
new Vec2i(width[0], height[0])
|
||||
));
|
||||
} else {
|
||||
tex = window.loadTexture(new Image(Vec2i.ZERO));
|
||||
tex = window.loadTexture(new Image32(Vec2i.ZERO));
|
||||
}
|
||||
stbtt_GetCodepointHMetrics(info, ch, advanceWidth, leftSideBearing);
|
||||
var c = new Char(tex,
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.danitheskunk.skunkworks.gfx.threedee;
|
|||
|
||||
import com.danitheskunk.skunkworks.IWindow;
|
||||
import com.danitheskunk.skunkworks.gfx.ITexture;
|
||||
import com.danitheskunk.skunkworks.gfx.Image;
|
||||
import com.danitheskunk.skunkworks.gfx.Image32;
|
||||
import org.lwjgl.assimp.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -52,7 +52,7 @@ public class Model {
|
|||
var texPB = ai.mTextures();
|
||||
for(int i = 0; i < numTextures; ++i) {
|
||||
var aiTex = AITexture.create(texPB.get(i));
|
||||
var img = new Image(aiTex.pcDataCompressed());
|
||||
var img = new Image32(aiTex.pcDataCompressed());
|
||||
var tex = window.loadTexture(img);
|
||||
textures[i] = tex;
|
||||
System.out.printf("tex %dx%d\n", img.getWidth(), img.getHeight());
|
||||
|
|
Loading…
Reference in New Issue