I have yet another question regarding SDL2.
I have some drawSprite
& drawBackround
& drawText
functions, all draw to the screen. They do this by creating a new surface, turning it into a new texture, rendering the texture, then destroying/freeing everything.
This worked fine until I wanted to put it in a very fast loop. There was a slight delay (or something) which caused images on the screen to flicker. (It would draw a background, draw sprites, draw text, then loop. So this caused the sprites to flicker.)
I looked up the issue, and found that you shouldn't create and destroy a texture every single frame, AKA allocate and deallocate memory every single frame. So, I created some a global texture and surface variables, with the intent to re-assign these variables every time I called any of the drawing functions, and then destroy them when the program closed. (Reduce, Reuse, Recycle!)
This did not work. My memory required by my program ballooned upward into the gigabytes, which made it totally unresponsive. Through some trial and error, I found that I STILL had to run DestroyTexture and FreeSurface functions at the end of each drawing function. I don't understand why this is, since I'm reusing the variables.
Anyways, once I added those back in I've found that my program is working but is MUCH SLOWER in rendering than before!!! Why is this??? What did I do wrong? (again)