Hi
I’ve got some experience with old fashioned OpenGL (with glBegin etc) and I’m trying to learn the newer versions. I’m trying to render a texture and failing. I have all my shaders, VAOs and texture loading libraries etc in place and working, but binding and drawing the texture is really fiddly. The following code for the binding works, sort of:
glGenTextures(1,&id);
glBindTexture(GL_TEXTURE_2D,id);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,res.x,res.y,0,GL_RGBA,GL_FLOAT,pix);
glGenerateMipmap(GL_TEXTURE_2D);
But it causes memory leaks. When I create and destroy many of these textures, the memory usage explodes. Commenting out this line fixes the memory leak:
glGenTextures(1,&id);
glBindTexture(GL_TEXTURE_2D,id);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,res.x,res.y,0,GL_RGBA,GL_FLOAT,pix);
//glGenerateMipmap(GL_TEXTURE_2D);
But now it doesn’t draw at all (or it draws a transparent texture instead). It shouldn’t need a mipmap, should it?
Also, it seems that the memory leak doesn’t appear for texture sizes below a certain threshold. A 256x256 texture works perfectly, with no leaks, but a 256x257 texture leaks like crazy!
Should I be deleting the mipmaps when I call glDeleteTextures(1,&id); or something?
I’ve been working on this one issue all day, and I’m at the point where I’m tempted to accept the memory leak. Any help would be greatly appreciated.