#include<SDL.h> //Creates an SDL Texture in a very unefficient manner SDL_Texture* CreateTexture(SDL_Renderer*& render, int width, int height) { //Create and fill a surface SDL_Surface *s = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 255); SDL_FillRect(s, NULL, SDL_MapRGB(s->format, 255, 255, 255)); //makes it all white //Create texture from surface SDL_Texture *t = SDL_CreateTextureFromSurface(render, s); //Free the surface SDL_FreeSurface(s); return t; } int main(int argc, char** argv) { //Make a window and renderer SDL_Window* window = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 200, 200, SDL_WINDOW_SHOWN); SDL_Renderer* render = SDL_CreateRenderer(window, -1, 0); //Get a texture going, make it blue!! SDL_Texture* t = CreateTexture(render, 200, 200); SDL_SetTextureColorMod(t, 0, 0, 255); //Draw texture to renderer SDL_RenderCopy(render, t, NULL, NULL); //Show the rendererererer SDL_RenderPresent(render); //Hold on for enough time to see it SDL_Delay(5000); //Destory everything SDL_DestroyTexture(t); SDL_DestroyWindow(window); SDL_DestroyRenderer(render); return 0; }The CreateTexture function uses SDL_CreateTextureFromSurface() instead of SDL_CreateTexture() because I haven't found a good description or explanation that can describe it to me (I am far from a computer scientist).
If I pass the renderer object through the CreateTexture function, does it destroy the reference at the end of the function or when I destroy it at the end of main()? Does it matter if I replace *& with *?
I'm sorry if the answer is super obvious, but I am super paranoid when it comes to my programs leaking memory or not freeing up the memory.
Thanks