查看我的旧代码,这甚至可以工作
ByteBuffer buf = null;
try{
texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/" + key + ".png"));
int texId = texture.getTextureID();
buf = ByteBuffer.allocateDirect(4*texture.getImageWidth()*texture.getImageHeight());
}catch(IOException e){
e.printStackTrace();
}
// Create a new texture object in memory and bind it
//int texId = GL11.glGenTextures(); - if the trick with texture.getTextureID() won't work - use THIS
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
// All RGB bytes are aligned to each other and each component is 1 byte
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
// Upload the texture data and generate mip maps (for scaling)
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, texture.getImageWidth(), texture.getImageHeight(), 0,
GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
//then you can generate some mipmaps
//Setup the ST coordinate system
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
// Setup what to do when the texture has to be scaled
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
你需要的是texId
.
我希望你知道如何使用纹理;)。