pull/12/head
hayden v 2020-03-02 12:31:23 +10:00
parent 06817492af
commit 202e0f1324
5 changed files with 34 additions and 19 deletions

View File

@ -40,7 +40,7 @@ public class Block
private final boolean visible, fullCube; private final boolean visible, fullCube;
private final float caveCarveThreshold; private final float caveCarveThreshold;
public final String identifier; public final String identifier;
private String texture; public String texture;
public boolean isFullCube() public boolean isFullCube()
{ return this.fullCube; } { return this.fullCube; }
@ -67,11 +67,17 @@ public class Block
this.fullCube = properties.fullCube; this.fullCube = properties.fullCube;
this.identifier = properties.identifier; this.identifier = properties.identifier;
this.caveCarveThreshold = properties.caveCarveThreshold; this.caveCarveThreshold = properties.caveCarveThreshold;
if(model != null) {
this.texture = model.getTexture().getTexture().getLocation();
}else {
this.texture = "DONTLOAD";
}
IDENTIFIER_TO_BLOCK.put(this.identifier, this); IDENTIFIER_TO_BLOCK.put(this.identifier, this);
Blocks.blocks.add(this); Blocks.blocks.add(this);
} }
public void updateBlockModel() { public void updateBlockModelData() {
System.out.println("Updating block with texture at block/"+texture);
this.model = ModelLoader.loadGenericCube("block/"+texture); this.model = ModelLoader.loadGenericCube("block/"+texture);
} }

View File

@ -7,7 +7,7 @@ import com.github.halotroop.litecraft.types.block.Block.Properties;
public final class Blocks public final class Blocks
{ {
public static ArrayList<Block> blocks = new ArrayList<Block>();//real number is 256 //TODO: get all mods to say how many blocks they have and increace the number by that public static ArrayList<Block> blocks = new ArrayList<Block>();
public static final Block AIR = new Block(new Properties("air").visible(false).fullCube(false)); public static final Block AIR = new Block(new Properties("air").visible(false).fullCube(false));
public static final Block GRASS = new Block(new Properties("cubes/soil/grass/grass_top.png").caveCarveThreshold(0.04f)); public static final Block GRASS = new Block(new Properties("cubes/soil/grass/grass_top.png").caveCarveThreshold(0.04f));

View File

@ -71,6 +71,7 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
shader.loadFakeLightingVariable(true); shader.loadFakeLightingVariable(true);
shader.loadShine(1, 1); shader.loadShine(1, 1);
GL13.glActiveTexture(GL13.GL_TEXTURE0); GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, atlasID);
enableWireframe(); enableWireframe();
} }
@ -85,7 +86,7 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
if (entity != null && entity.getModel() != null) if (entity != null && entity.getModel() != null)
{ {
TexturedModel blockModel = entity.getModel(); TexturedModel blockModel = entity.getModel();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, atlasID); GL11.glBindTexture(GL11.GL_TEXTURE_2D, blockModel.getTexture().getTextureID());
prepBlockInstance(entity); prepBlockInstance(entity);
GL11.glDrawElements(GL11.GL_TRIANGLES, blockModel.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0); GL11.glDrawElements(GL11.GL_TRIANGLES, blockModel.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
} }

View File

@ -34,20 +34,22 @@ public class Image
img = stbi_load_from_memory(imageBuffer, w, h, comp, 0); img = stbi_load_from_memory(imageBuffer, w, h, comp, 0);
if (img == null) if (img == null)
{ throw new RuntimeException("Failed to load image: " + stbi_failure_reason()); } { throw new RuntimeException("Failed to load image: " + stbi_failure_reason()); }
return new Image(w.get(0), h.get(0), img, comp); return new Image(w.get(0), h.get(0), img, comp, imagePath);
} }
} }
private ByteBuffer image; private ByteBuffer image;
private int width, height; private int width, height;
private IntBuffer comp; private IntBuffer comp;
private String location;
Image(int width, int heigh, ByteBuffer image, IntBuffer comp) Image(int width, int heigh, ByteBuffer image, IntBuffer comp, String location)
{ {
this.image = image; this.image = image;
this.height = heigh; this.height = heigh;
this.width = width; this.width = width;
this.comp = comp; this.comp = comp;
this.location = location;
} }
public int getHeight() public int getHeight()
@ -61,4 +63,8 @@ public class Image
public IntBuffer getComp() public IntBuffer getComp()
{ return comp; } { return comp; }
public String getLocation() {
return location;
}
} }

View File

@ -120,25 +120,27 @@ public class Loader
//Fill the image with blank image data //Fill the image with blank image data
GL40.glTexImage2D(GL40.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width*2, height*2, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); GL40.glTexImage2D(GL40.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width*2, height*2, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
int maxX = (int) Math.sqrt(Blocks.blocks.size());//if the block list gets too big just increace the 2 by 4 or somthing to account for it long maxX = Math.round(Math.sqrt(Blocks.blocks.size()));
int currentX = 0; int currentX = 0;
int currentY = 0; int currentY = 0;
for(Block block: Blocks.blocks) { for(Block block: Blocks.blocks) {
//just in case //just in case
block.updateBlockModel(); if(!block.texture.equals("DONTLOAD")) {
block.updateBlockModelData();
if(currentX > maxX) { if(currentX > maxX) {
currentX = 0; currentX = 0;
currentY--; currentY--;
}
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0,
currentX*width, currentY*height,
width, height,
GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,
block.model.getTexture().getTexture().getImage()
);
currentX++;
} }
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0,
currentX*width, currentY*height,
width, height,
GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,
block.model.getTexture().getTexture().getImage()
);
currentX++;
} }
return atlasId; return atlasId;
} }