Reloading a texture

So I currently use a texture class , however this class is quite limiting as you have to load it in before you setup the textures. So the issue comes when for instance I load in a spritesheet create object A , then I load in spritesheet buttons , then I create tile B and the issue comes where B gets a buttons texture and not a tile texture. Here is the example of it using my text renderer.

What happens is that when I load in the new texture every other texture freaks out.
Here is my GB class that generates the VBOS (each tile, text, GUI , image has its own vbo which I will sort out later)

package com.Core.graphics;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;

import com.Core.Gamecore;
import com.Core.Util.Translationhelper;
import com.Core.graphics.shader.Shaderclass;
import com.Core.graphics.texture.Texture;

public class GB {// Sepeartely used object only.
	private FloatBuffer verticies;
	private FloatBuffer texcoord;
	private int vertid, texid;
	public vertex2d translation;
	private Texture t;
	private int transformid, scalarid, vertcount;
	private float scalar;
	private Translationhelper th;
	private Gamecore gc;
	private Shaderclass shader;

	public GB(Gamecore gc) {
		shader = new Shaderclass();
		shader.attachVertexShader("com/Core/graphics/shader/shaders/vertshader.vert");
		shader.attachFragmentShader("com/Core/graphics/shader/shaders/fragshader.frag");
		shader.link();
		transformid = GL20.glGetUniformLocation(shader.programID, "transform");
		scalarid = GL20.glGetUniformLocation(shader.programID, "scalar");
		scalar = gc.verticalaspect;
		th = new Translationhelper();
		th.setsize(gc.width, gc.height);
		this.gc = gc;
	}

	public void createobject(vertex2d[] object, Texture t, int texunit) {
		GL11.glEnable(GL11.GL_TEXTURE_2D);
		GL11.glEnable(GL11.GL_BLEND);
		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
		translation = new vertex2d(0, 0);
		verticies = BufferUtils.createFloatBuffer(2 * object.length);
		texcoord = BufferUtils.createFloatBuffer(2 * object.length);
		for (int i = 0; i < object.length; i++) {
			verticies.put(object[i].getx());
			verticies.put(object[i].gety());
			texcoord.put(object[i].gets());
			texcoord.put(object[i].gett());
		}
		verticies.rewind();
		texcoord.rewind();
		vertid = GL15.glGenBuffers();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticies, GL15.GL_DYNAMIC_DRAW);
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
		vertcount = object.length;
		texid = GL15.glGenBuffers();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texid);
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, texcoord, GL15.GL_DYNAMIC_DRAW);
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
		this.t = t;
		bindtexture(texunit);
	}

	public void bindtexture(int texunit) {
		int loc = GL20.glGetUniformLocation(shader.programID, "tex");
		if (loc != -1) {
			GL20.glUniform1i(loc, texunit);

			if (texunit == 0) {
				GL13.glActiveTexture(GL13.GL_TEXTURE0);
			} else if (texunit == 1) {
				GL13.glActiveTexture(GL13.GL_TEXTURE1);
			} else if (texunit == 2) {
				GL13.glActiveTexture(GL13.GL_TEXTURE2);
			} else if (texunit == 3) {
				GL13.glActiveTexture(GL13.GL_TEXTURE3);
			}

		} else {
			System.err.println("WARNING: NO VARIABLE DETECTED WITHIN SHADER");
		}

	}

	public void translate(float f, float g) {
		vertex2d transformed = th.transform((f*2) - (gc.width), (
				g*2) +(gc.height));
		translation.setcoordinates(transformed.getx(), transformed.gety());
	}

	public void forcetranslate(float f, float g) {
		translation.setcoordinates(f, g);
	}

	public void render() {
		shader.bind();

		// Bind the vertex buffer
	//	t.bindtex(t.id, t.width, t.height, t.buffer);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, t.id);
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
		GL20.glEnableVertexAttribArray(0);
		GL20.glEnableVertexAttribArray(1);
		GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, 0, 0);
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texid);
		GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 0, 0);
		GL20.glUniform2f(transformid, translation.getx(), translation.gety());
		GL20.glUniform1f(scalarid, scalar);
		// Draw the textured rectangle
		GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertcount);

		GL20.glDisableVertexAttribArray(0);
		GL20.glDisableVertexAttribArray(1);
		shader.unbind();
	}

	public void destroy() {
		if (Display.isActive()) {
			GL15.glDeleteBuffers(vertid);
			GL15.glDeleteBuffers(texid);
		}
		shader.dispose();
	}


}


package com.Core.graphics.texture;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.ByteBuffer;

import javax.imageio.ImageIO;

import org.lwjgl.BufferUtils;

import static org.lwjgl.opengl.GL11.*;
//Many thanks to SHC for the tutorial on this
public class Texture {
	public int id;

	public int width;

	public int height;

	public ByteBuffer buffer;
	private Texture(int id, int width, int height, ByteBuffer buffer) {
		this.id = id;
		this.width = width;
		this.height = height;
		this.buffer = buffer;
	}
	public Texture(){
		
	}

	public static 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[0]);
		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 if(pixels[y * bimg.getWidth() + x] != -1){
					buffer.put((byte)0);
					buffer.put((byte)0);
					buffer.put((byte)0);
					buffer.put((byte)0);
				}
				else{
					buffer.put((byte)-1);
					buffer.put((byte)-1);
					buffer.put((byte)-1);
					buffer.put((byte)-1);
				}
			}
		}
		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(),buffer);
	}
	public void bindtex(int textureID,int width , int height ,ByteBuffer buffer){
		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, width,
				height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
	}
}


At the bottom (bindtex) is my attempt to remedy the issue by reloading the texture in just before I render the vbo.
Im not the best with OpenGL so its going straight over me. From what I can see though its loading the texture which is messing with the other stored textures causing them to render as the last loaded texture

Instead of having nested if statments to load bind a texture do this:

GL13.glActiveTexture(GL13.GL_TEXTURE0+t.id);

That might help, but I not sure what your problem is. Can you load all your current textures and they are fine, but if you load more it breaks?

Ill show you the code that handles , I have had to order it because of this issue but only now has it become detrimental

spritesheet iconsheet = new spritesheet(
				"com/Core/graphics/texture/sprites/icon.png");

		icon.createobject(
				world.shape.rect(iconsheet.getcoords(0, 0, 199, 149), (int) width,(int)height),
				iconsheet.gettexture(), 1);
		icon.translate(0,-(int)height);
//		m = new Mouselistener(this); depreciated
		
		logger.log("LOGGING STARTED OF SOLIS");

		button = new spritesheet("com/Core/graphics/texture/sprites/Button.png");
		game = new Game(this);
		// WORLD AND TILE SETUP

so all of that is done in order , all the GUI generation is done before all of the manipulateable stuff.
so if I load the iconsheet texture after the button texture , even though they are entirely different textures the issue will occur.

Realisation moment , im using a texture loader then a spritesheet class , maybe the spritesheet is interfering LUCAS AWAY!

So it turns out that thats not the issue , the issue appears to be caused by the way the text is rendered itself , ill have to play around with it . It was overloading the textures because I was loading in the texture before the constructor directly as a variable. Dont know why that messed it all up but that bits fixed now to stop it blanking the screen.

im slowly isolating the issue but this will take a while.

traced it down to a method Bindtexture call. It set the active texture slot .

Cool so it’s working now?

how many objects do you spawn ?

each should have a different pipe assigned, right ?

What was happening is I was requesting a texunit from the user , when I did this it changed what was being rendered so that all the textures were equal to what is curently on this texunit , so I removed that and it works now. Implementing my inventory, im in very early stages but I have big plans for this. check it out , SOLIS under WIP