Texture is binding in places it shouldn't

Hi

So I have a texture bound for one screen, and when I am bounding other textures somewhere else, the original textures are being bound instead. Here’s where the original one was bound:


   glEnable(GL_TEXTURE_2D);
				texture.bind();
				glBegin(GL_QUADS);
					glTexCoord2f(0, 0);
					glVertex2f(xOffset, yOffset);
					glTexCoord2f(1, 0);
					glVertex2f(xOffset + 72.0f, yOffset);
					glTexCoord2f(1, 1);
					glVertex2f(xOffset + 72.0f, yOffset + 72.0f);
					glTexCoord2f(0, 1);
					glVertex2f(xOffset, yOffset + 72.0f);
				glEnd();
				glDisable(GL_TEXTURE_2D);

And here is where it’s appearing


   glEnable(GL_TEXTURE_2D);
		icon.bind();
		glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2f(x, y);
			glTexCoord2f(1, 0);
			glVertex2f(x + width, y);
			glTexCoord2f(1, 1);
			glVertex2f(x + width, y + height);
			glTexCoord2f(0, 1);
			glVertex2f(x, y + height);
		glEnd();
		glDisable(GL_TEXTURE_2D);

This method binds textures:


   public void bind(){
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, textureID);
	}

This is my Texture class where the binding actually happens:


package warlord.opengl;

import static org.lwjgl.opengl.GL11.*;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import javax.imageio.ImageIO;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL12;

import warlord.files.Accessor;
import warlord.ingame.ObjectLoading;

public class Texture {
	
	private int textureID;
	private int width;
	private int height;
	private BufferedImage image;
	private static String source;
	
	public Texture(){
		// Empty!
	}
	
	public static Texture loadTexture(File file){
		source = file.getAbsolutePath();
		try {
			BufferedImage bImage = ImageIO.read(file);
			return new Texture(bImage);
		} catch (IOException e) {
			if(Game.isDebug()){
				System.out.println("Image couldn't be read");
				e.printStackTrace();
			}
			return null;
		}
	}
	
       // This method seems to be what determines the bound texture not what glBindTexture binds.
@@	public static Texture loadTexture(String filename){
		source = filename;
		if(TextureLoader.getTexture(filename) != null){
			return TextureLoader.getTexture(filename);
		}
		if(filename.endsWith(".resource")){
			// Serialized buffer
			try {
				SerializableBufferWrapper buffer = (SerializableBufferWrapper) ObjectLoading.loadObject(filename);
				return loadTexture(buffer, filename);
			} catch (ClassNotFoundException | IOException e) {
				File textureFile = null;
				try {
					textureFile = new File(Accessor.class.getResource(filename).toURI());
				} catch (URISyntaxException e1) {
					e1.printStackTrace();
				}
				return loadTexture(textureFile);
			}
		} else {
			File textureFile = null;
			try {
				textureFile = new File(Accessor.class.getResource(filename).toURI());
			} catch (URISyntaxException e) {
				if(Game.isDebug()){
					e.printStackTrace();
				}
			}
			return loadTexture(textureFile);
		}
	}
	
	public static Texture loadTexture(SerializableBufferWrapper buffer, String filename){
		source = filename;
		return new Texture(buffer);
	}

	public void scaleActual(float scale){
		int height_ = Math.round(height * scale);
		int width_ = Math.round(width * scale);
		setSize(width_, height_);
	}
	
	public String getSource(){
		return source;
	}
	
	public Texture scale(float scale) throws CloneNotSupportedException{
		Texture texture = (Texture) clone();
		int height_ = Math.round(height * scale);
		int width_ = Math.round(width * scale);
		texture.setSize(width_, height_);
		return texture;
	}
	
	public void setSize(int width, int height){
		this.width = width;
		this.height = height;
	}
	
	public Texture(BufferedImage image){
		this.image = image;
		IntBuffer idBuffer = BufferUtils.createIntBuffer(1);
		glGenTextures(idBuffer);
		textureID = idBuffer.get(0);
		loadTexture(image);
	}
	
	public Texture(SerializableBufferWrapper buffer){
		IntBuffer idBuffer = BufferUtils.createIntBuffer(1);
		glGenTextures(idBuffer);
		textureID = idBuffer.get(0);
		loadTexture(buffer.buffer, buffer.width, buffer.height);
	}
	
	public void bind(){
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, textureID);
	}
	
	public static void unbind(){
		glDisable(GL_TEXTURE_2D);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, 0);
	}
	
	public int getHeight(){
		return height;
	}
	
	public int getWidth(){
		return width;
	}
	
	public BufferedImage getImage(){
		return image;
	}
	
	public void loadTexture(byte[] buffer_, int width, int height){
		glEnable(GL_TEXTURE_2D);
		this.width = width;
		this.height = height;
		ByteBuffer buffer = BufferUtils.createByteBuffer(buffer_.length).put(buffer_); // Clone the buffer
		buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS
        glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID
       //Setup wrap mode
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
       //Setup texture scaling filtering
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
       //Send texel data to OpenGL
       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
	}
	
	public void loadTexture(BufferedImage image){
		glEnable(GL_TEXTURE_2D);
		width = image.getWidth();
		height = image.getHeight();
	      int[] pixels = new int[image.getWidth() * image.getHeight()];
	        image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
	        ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4); 
	        for(int y = 0; y < image.getHeight(); y++){
	            for(int x = 0; x < image.getWidth(); x++){
	                int pixel = pixels[y * image.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));
	            }
	        }
	        buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS
	         glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID
	        //Setup wrap mode
	        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
	        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
	        //Setup texture scaling filtering
	        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	        //Send texel data to OpenGL
	        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
	        glBindTexture(GL_TEXTURE_2D, 0); // Clear the texture
	}

}


The texture is originally bound in the BlockScreen sclass, but it is still there in the Entity class, which aren’t even rendered in the same frame. I hope somebody can help me :slight_smile:

CopyableCougar4