1

I have a function which loads an image/text into my game.I'm using gluBuild2DMipmaps() to make an OpenGL texture from the SDL surface.The problem is that everytime when I call that function, even if I load the same image and bind it on the same texture, gluBuild2DMipmaps allocates 0.5MB of memory which is not released until I close the program.
My function:

void Load_texture(const char * text, SDL_Color clr, int txtNum, const char* file, int ptsize, bool type){
if(type){
         tmpfont = TTF_OpenFont(file, ptsize); 
         sText = TTF_RenderUTF8_Blended( tmpfont, text, clr );
         TTF_CloseFont(tmpfont);
}
if(!type)sText = IMG_Load(file);
area[txtNum].x = 0;area[txtNum].y = 0;area[txtNum].w = sText->w;area[txtNum].h = sText->h;
glGenTextures(1, &texture[txtNum]);
glBindTexture(GL_TEXTURE_2D, texture[txtNum]);
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, sText->w, sText->h, GL_RGBA, GL_UNSIGNED_BYTE, sText->pixels );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR );
SDL_FreeSurface( sText ); 
}

What can I do to release the memory allocated by gluBuild2DMipmaps, because now my game uses almost 1GB of RAM one minute after it starts.

slaviber
  • 358
  • 2
  • 10
  • Note: [`GL_TEXTURE_MAG_FILTER`](http://www.opengl.org/wiki/Texture#Filtering) *cannot* be set to `GL_LINEAR_MIPMAP_LINEAR`. That would not make sense, as mipmaps are for minification of textures. The magnifying filter cannot make use of them. You probably just want `GL_LINEAR`. – Nicol Bolas Jan 29 '12 at 17:15

1 Answers1

1

Are you sure you free the texture itself? Do you call

glDeleteTextures(1, &texture[txtNum]);

...before reusing the txtNum texture?

Kornel Kisielewicz
  • 55,802
  • 15
  • 111
  • 149