I try to texture a cube with a bmp file. I did but I have a problem about memory. Memory usage of my program increases without stopping. When I want to esc, an error message occurs “Debug Error …path…/.exe Damage: After Normal block (#1773 at 0x09f3ae58. Please retry t debug application”.
How can I solve this problem?
Be sure that the part that reads the bmp and does glTexImage2D is called only once near the start of the program, and NOT called at each display refresh.
At each display refresh I call glTexImage2D. The program is working as I want. But memory usage of my program increases without stopping.
You have to call glTexImage2D only once, at loading. After that use glBindTexture(GL_TEXTURE_2D, texture_id);
Your program uploads the texture to the video ram every frame.
That’s one reason why. Here’s the way to think about this API call:
- glTexImage2D: malloc and memcpy
- glTexSubImage2D: memcpy
You call glTexImage2D “once” per MIPmap level to allocate. You can even call it with a NULL pointer (with no PBO bound) to do the malloc but not the memcpy (i.e. leave the contents of the memory block unspecified). Then you call glTexSubImage2D one or more times to change the contents of that MIPmap’s memory block.