Freeing generated textures

Started by
5 comments, last by Gunner 23 years, 3 months ago
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.
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.

btw. Sorry for the big fonts, It''s copy-pasted from the MSDN...
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
"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);

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/
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Super !

It''s much clearer now.
Thanks guys,

Gunner.

This topic is closed to new replies.

Advertisement