Texture Farm

I have a conceptual question, I simply don’t know the right terms or ideas to look for what I want.

I want to be able to load my textures and put their variables in some globally accessible location. Like a utility class, but that can only be referenced static-ly right?

I want to be able to assign a textureID to an object, but I don’t want to always pass around an array of ints or however I’d manage them.

Is it possible to do something like this? Using LWJGL3 if that matters.

Sure, anything is possible. It really depends on exactly what you want to do.

You could use a Map<Integer, Texture> that maps from id keys to Texture (or whatever class represents a texture) values.

Or you could use an enum that represents you textures, or objects, or… there are a million different ways to do this.

What have you tried so far? What exactly are you confused about? Where did you get stuck?

I get lost at accessing this data. I make an object, and in that object’s constructor I just want it to be able to say, int texID = textureFarmArray[]. I want that textureFarmArray to be populated in another class (priorly). I need to not have to pass the array or ID as an argument to the object.

I’m not sure I follow. How do you expect the object to know which texture to use?

The array holds the texture IDs. texID is populated from the array. My trouble is in understanding how to make that array accessible to the object.

Well, you either need to pass it into the object as an argument, or you need to make it available statically.

But we’re talking about two different things here: there’s the overall “texture farm” that holds the texture ids and the images they map to, and then there’s the individual ids for each object to tell it which texture to use.

Think I got it. Just gotta get a little creative. Think I’ve got a solution formulated. Thanks for help :slight_smile:

No problem. I’d be curious to hear about what you come up with.

This is a port from a non-OpenGL build. Originally, these objects held their Image. Now I will have the corresponding ImageObjects live on the main class. When it comes time to draw one of these objects, I will reference the array that is holding the ImageObjects and draw the one that matches the object type. The array will be populated in order so it’s just object type = array index.