Last question I asked was about how to draw different models in OpenGL. I got that covered, but now I'm stuck at doing textures. Once again I can easily get textures to work, as long as I only ever use one texture.
The class that loads the textures:
public class Textures
{
public static int tex, tex2;
public static void load() throws IOException
{
tex = glGenTextures();
tex2 = glGenTextures();
load(tex2, "moreModels/robot.jpg", "jpg");
load(tex, "moreModels/sample.jpg", "jpg");
}
public static void load(int tex, String name, String type) throws IOException
{
glBindTexture(GL43.GL_TEXTURE_2D, tex);
glTexParameterIi(GL43.GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterIi(GL43.GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glGenerateMipmap(GL43.GL_TEXTURE_2D);
glTexParameterIi(GL43.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterIi(GL43.GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
Texture texture = TextureLoader.getTexture(type, ResourceLoader.getResourceAsStream(name));
byte[] pixels = texture.getTextureData();
ByteBuffer buffer = BufferUtils.createByteBuffer(pixels.length);
buffer.put(pixels);
buffer.flip();
glTexImage2D(GL43.GL_TEXTURE_2D, 0, GL_BGR, texture.getImageWidth(), texture.getImageHeight(), 0, GL_BGR, GL_BYTE, buffer);
}
}
Now, I would think that simply calling glBindTexture(GL43.GL_TEXTURE_2D, textureID) will change the texture, but no. If I at any time call the glBindTexture method everything will be rendered black.
Is it the same as before, where I have to do the entire load method every time I need to change the texture? (Perhaps saving the Texture object, so I don't have to load it over and over again). And if so, what's the point of having glGenTextures() when it aparently forgets everything about it when changed?