LWJGL Forum

Programming => OpenGL => Topic started by: Eistoeter on December 30, 2008, 10:17:55

Title: How to free loaded textures properly?
Post by: Eistoeter on December 30, 2008, 10:17:55
Hi

My game can load and display textures now which is very nice. However I'm a little bit unsure how to properly unload these again to free memory?

The following seems not to be enough because I can still bind the texture and display it so I suppose it has not really been freed:


public void deleteTexture(String path) {
                // textures is a TreeMap with Strings as keys
                // and texture objects as values.
                // a texture object saves its id generated by OpenGL
                // which I request here trough getter
int id = textures.get(path).getId();

IntBuffer intBuffer = IntBuffer.wrap(new int[] { id });
GL11.glDeleteTextures(intBuffer);
textures.remove(path);
}
Title: Re: How to free loaded textures properly?
Post by: Evil-Devil on December 31, 2008, 11:36:41
If you cleared the NIO Buffer you've used to load and upload the texture your done with it.
With glDeleteTextures the texture is removed from the graphiccards RAM and need to be loaded again.

If iam wrong, please correct me :)
Title: Re: How to free loaded textures properly?
Post by: Eistoeter on December 31, 2008, 11:47:12
But why can I still bind and render the texture then?  ???
Title: Re: How to free loaded textures properly?
Post by: Evil-Devil on December 31, 2008, 13:11:34
It may that you have bind the texture while attempting to delete it. Then the delete process will fail i think.

I found this within the OGL Documentation.
QuoteIf a   texture that is
     currently bound is deleted, the binding reverts to 0 (the
     default texture).

Try to unbound the texture first and delete it then. Should work.
Title: Re: How to free loaded textures properly?
Post by: Eistoeter on January 02, 2009, 13:21:47
Thanks everything works fine right now.