• Advertisement

Archived

This topic is now archived and is closed to further replies.

Freeing generated textures

This topic is 6249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, how can i free a texture once it has been created ? i use the standard ''glGenTextures and glbindtexture'' Once my texture is bound, i assume i would use that reference to free it correct ? My game is multi-level, like all other games i guess, and when one level ends, i need to load new textures. So my guess would be to delete the textures i no longer need and create/load new ones. Is there a GL call to free those texture or do i simply point them to nil ? much appreciated, thanks, Gunner.

Share this post


Link to post
Share on other sites
Advertisement

glDeleteTextures



The glDeleteTextures function deletes named textures.


void glDeleteTextures(
GLsizei
n,
const GLuint * textures
);

Parameters




n


The number of textures to be deleted.


textures


An array of textures to be deleted.


Remarks



The glDeleteTextures function deletes n textures named by the elements of the array textures. After a texture is deleted, it has no contents or dimensionality, and its name is free for reuse (for example, by glGenTextures). The glDeleteTextures function ignores zeros and names that do not correspond to existing textures.



If a texture that is currently bound is deleted, the binding reverts to zero (the default texture).



You cannot include calls to glDeleteTextures in display lists.



Note The glDeleteTextures function is only available in OpenGL version 1.1 or later.

Share this post


Link to post
Share on other sites
Thanks, that''s exactly what i was looking for.

I generate my texture like so:

glGenTextures(1, @Texture[0]);
glBindTexture(GL_Texture_2D, Texture[0]);

soo to delete i would use ? :

glBindTexture(GL_Texture_2D, Texture[0]);
glDelete(GL_Texture_2D,Texture[0]);

It''s delphi but OpenGL is very simillar from language to language.

Gunner

Share this post


Link to post
Share on other sites
"glBindTexture(GL_Texture_2D, Texture[0]);
glDelete(GL_Texture_2D,Texture[0]);"

Nope. One, you dont need the first line, second, where you have gl_texture_2d is actually where you need to specify how many textures you want deleted from the array ''Texture''.

So you should have, if you only wanted to delete Texture[0]:

glDeleteTextures(1,Texture);

if you wanted to delete Texture[0] and Texture[1] then:

glDeleteTextures(2,Texture);

Im not sure if the array Texture needs to be represented as a pointer :/ so try

glDeleteTextures(1,@Texture);

Share this post


Link to post
Share on other sites
Code form one of my progs.

GLuint texture = 0;

... ...

bool GenerateTexture(){
if(!texture)
glGenTextures(1,&texture);
if(!texture)
return false;

... ...

if(texture)
glDeleteTextures(1,&texture);
texture = 0;

Hope that helps.
l8r,
Rob
http://tannara.2y.net/

Share this post


Link to post
Share on other sites

  • Advertisement