In your function
SDL_Surface *loadIMG(std::string filename, SDL_Surface *image, SDL_Surface *imageOPT);
the pointer imageOPT is being copied at function call here :
loadIMG("arena.png", background, backgroundOPT);
This mean you're not setting backgroundOPT
, but a copy of it.
Simply do something like that :
backgroundOPT = loadIMG("arena.png", background, backgroundOPT);
Or change your function prototype to :
SDL_Surface *loadIMG(std::string filename, SDL_Surface *image, SDL_Surface **imageOPT);
and call it like that :
loadIMG("arena.png", background, &backgroundOPT);