Im having an issue where if I load 2 textures only the first texture is used in any situation , even if I use a seperate method it still shows only the first loaded texture.
here is my code.
public class Texture {
public int id;
public int width;
public int height;
private Texture(int id, int width, int height) {
this.id = id;
this.width = width;
this.height = height;
}
public Texture(){
}
public Texture loadTexture(String name) {
BufferedImage bimg = null;
try {
bimg = ImageIO.read(Texture.class.getClassLoader()
.getResourceAsStream(name));
} catch (IOException e) {
e.printStackTrace();
System.out.println("Texture loading failure! " + name);
}
int[] pixels = new int[bimg.getWidth() * bimg.getHeight()];
bimg.getRGB(0, 0, bimg.getWidth(), bimg.getHeight(), pixels, 0,
bimg.getWidth());
ByteBuffer buffer = BufferUtils.createByteBuffer(bimg.getWidth()
* bimg.getHeight() * 4);
System.out.println(pixels[65]);
for (int y = 0; y < bimg.getHeight(); y++) {
for (int x = 0; x < bimg.getWidth(); x++) {
if (pixels[y * bimg.getWidth() + x] != -65281) {
int pixel = pixels[y * bimg.getWidth() + x];
buffer.put((byte) ((pixel >> 16) & 0xFF));
buffer.put((byte) ((pixel >> 8) & 0xFF));
buffer.put((byte) (pixel & 0xFF));
buffer.put((byte) ((pixel >> 24) & 0xFF));
}
else{
buffer.put((byte)0);
buffer.put((byte)0);
buffer.put((byte)0);
buffer.put((byte)0);
}
}
}
buffer.flip();
int textureID = glGenTextures();
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, bimg.getWidth(),
bimg.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
return new Texture(textureID, bimg.getWidth(), bimg.getHeight());
}
}
public class spritesheet {
private Texture tex,load;
private float x,y,ex,ey,width,height;
public spritesheet(String location){
load = new Texture();
tex = load.loadTexture(location);
this.width = tex.width;
this.height = tex.height;
}
public spritecomponent getcoords(int x, int y, int ex,int ey){
spritecomponent temp= new spritecomponent();
this.x = x/width;
this.y = y/height;
this.ex = ex/width;
this.ey = ey/height;
temp.set(this.x, this.y, this.ex, this.ey, tex);
return temp;
}
public Texture gettexture(){
return tex;
}
}