1
\$\begingroup\$

When loading a texture in SDL2 the general procedure is this:

SDL_Texture* texture = IMG_LoadTexture(renderer, "resources/images/image.png);

However this doesn't work and I have to supply the WHOLE path to the specific image. The code that I have to use is:

SDL_Texture* texture = IMG_LoadTexture(renderer, "/home/user/programs/game/resources/images/image.png);

This issue doesn't occur in a Windows Mingw32 environment.

Any suggestion on how to fix this issue?

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

It's possible that you're running the executable in a different directory than the one that contains your resources folder.

If you need to change the directory from, say, a makefile, just cd to the desired base directory and run the executable from there.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Instead of makefile, the recommended way is to use SDL_GetBasePath() to access resources. \$\endgroup\$ Commented Feb 10, 2015 at 0:05
1
\$\begingroup\$

You can get this information with the following code:

char buffer[256];    
char *getcwd( buffer, 256 );

One hint: when the working directory differs from the place where the binary is stored: do you start the app from an IDE like QtCreator. If yes: please change the working directory for the run in your IDE.

\$\endgroup\$
1
  • \$\begingroup\$ Your hint helped also but the other answer was better \$\endgroup\$ Commented Aug 12, 2014 at 14:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .