I'm programming with SDL2, but I cannot grasp the reason behind the following. This works:
SDL_Window *window;
SDL_Surface *screen_surface;
SDL_Surface *picture;
auto initWindow(void)
{…}
auto loadMedia(void)
{…}
auto close(void)
{…}
int main(void)
{
initWindow();
loadMedia();
…
close();
}
However this does not:
auto initWindow(SDL_Window *window, SDL_Surface *screen_surface)
{…}
auto loadMedia(SDL_Surface *picture, std::string resource)
{…}
auto close(SDL_Window *window, SDL_Surface *picture)
{…}
int main(void)
{
SDL_Window *window;
SDL_Surface *screen_surface;
SDL_Surface *picture;
initWindow(window, screen_surface);
loadMedia(picture, "resource_file.bmp");
…
close(window, picture);
}
The only difference is that I take window
, screen_surface
and picture
out of file scope and put it into block scope (i.e. the main function), and instead of referencing global variables inside these functions, I use parameters.
However when I try to run this, it displays a white screen, but doesn't display any errors. I don't understand what goes wrong here.