Skip to main content
GameDev.net gamedev.net
🔒 Locked

Deleting a Texture

Started by medevilenemy Apr 13, 2009 at 12:05 AM 3 replies 1.2k views
Original Post
medevilenemy
medevilenemy
I've been trying to figure out how to unload my textures after I no longer need them, but I can't seem to figure out how. This is how I generate an individual texture:

    glBindTexture(GL_TEXTURE_2D, texnum);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, texture);
    free(texture);

where texture is temporary storage for the texture data while it was being loaded and generated. after free(texture); the texture data does not exist locally anymore... I think opengl stores it internally at that point -- so I can only access individual textures through their texture ids (texnum). Is there any way to delete a texture from within opengl knowing only its texture id?
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
medevilenemy
medevilenemy
it seems to be the correct function, but all the references on its use i've found use it to delete out of local storage (variables). I need a way to delete textures from wherever opengl stores them (the only way I can access them is through binding their tex ids)
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
mightypigeon
mightypigeon
Quote:
glDeleteTextures 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). If a texture that is
currently bound is deleted, the binding reverts to 0 (the
default texture).


So in your original example you would simply do something like:

glDeleteTextures( 1, &texnum );


The second parameter of glDeleteTextures is simply a pointer to a list of texture object ID's. It lets you do something like this

GLuint textures[5];textures[0] = loadtexture( "texture1.tga" );textures[1] = loadtexture( "texture2.tga" );...etc...glBindTexture( GL_TEXTURE_2D, textures[0] );then later onglDeleteTextures( 5, textures );


It's the same as glGenTextures, just in reverse :)
[size="1"]
medevilenemy
medevilenemy
that would work? Wow, thanks. My apologies for my denseness, I wasn't entirely certain how glDeleteTextures worked. Thanks again!
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.