I am trying to learn SDL2 by using C. My problem is that I am trying to avoid creating a global SDL_Window by doing this:
void init(SDL_Window *win){
SDL_Init(SDL_INIT_EVERETHING);
win = SDL_CreateWindow("PONG", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN);
}
int main(){
SDL_Window *window = NULL;
init(window);
if(window == NULL) printf("error!");
return 0;
}
The problem is that the window only "exists" in the init function call and the program still prints "error!", indicating that the window in main function is still a null pointer.
If I am doing this directly in main instead it works as supposed to (does not print "error!"):
int main(){
SDL_Window *window = NULL;
SDL_Init(SDL_INIT_EVERETHING);
window = SDL_CreateWindow("PONG", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN);
if(window == NULL) printf("error!");
return 0;
}
Thanks in advance.