I'm tryng to create a Minecraft clone, but my code render only one texture, i'm a opengl beginner, some help please? (I'm italian so excuse me for my bad english)
Here my Texture class
private String location;
private int id;
private boolean loaded = false;
public Texture(String location) {
this.location = location;
}
public void loadTexture() {
if (!this.loaded) {
this.loaded = true;
try {
InputStream stream = new FileInputStream("Textures/" + this.location);
PNGDecoder decoder = new PNGDecoder(stream);
ByteBuffer buffer = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
decoder.decode(buffer, decoder.getWidth() * 4);
buffer.flip();
this.id = GL11.glGenTextures();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.id);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public int getId() {
return this.id;
}
my chunk data class that renderize
public class ChunkData {
private final Vector3i chunkPos;
private final Block[][][] blocks;
public ChunkData(Vector3i pos) {
this.chunkPos = new Vector3i(pos);
this.blocks = new Block[16][16][16];
}
public static boolean inChunk(int x, int y, int z) {
return x >= 0 && y >= 0 && z >= 0 && x < 16 && y < 16 && z < 16;
}
public void setBlockAt(int x, int y, int z, Block block) {
if (inChunk(x, y, z)) {
this.blocks[x][y][z] = block;
}
}
public Block getBlockAt(int x, int y, int z) {
if (inChunk(x, y, z)) {
return this.blocks[x][y][z];
}
return null;
}
public Vector3i getChunkPos() {
return this.chunkPos;
}
public void render() {
blocks[1][1][2].getTexture().loadTexture();
blocks[2][2][1].getTexture().loadTexture();
}
}
there are 2 blocks, one contains this texture
@Override
public Texture getTexture() {
return new Texture("Dirt.png");
}
and another is this
@Override
public Texture getTexture() {
return new Texture("Stone.png");
}
the blocks[1][1][2] contains a Stone texture and the [2][2][2] a Dirt texture but when i run the program it displays both as a stone texture.