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.
Are you sure you free the texture itself? Do you call
…before reusing the txtNum texture?