Files & storageSDL 3.2
SDL_GetBasePath
The folder the program was started from (next to the executable). Where your read-only assets live.
Signature
const char * SDL_GetBasePath(void);
How it works
Relative paths such as "assets/player.png" are relative to the CURRENT directory, which depends on how the program was launched (a double-click, a terminal elsewhere, the IDE). Building paths from the base path makes asset loading work no matter where it was started from.
The string always ends with a path separator, so just append the file name. On macOS app bundles it is the bundle's Resources folder.
Return value
An absolute UTF-8 path owned by SDL (SDL3 caches it: do NOT free it, unlike SDL2), or NULL if unknown.
Tips & pitfalls
Treat it as read-only. Installed programs usually cannot write there; save games go in
SDL_GetPrefPath.
Example
example.cpp
1std::string asset(const char* name) {
2 return std::string(SDL_GetBasePath()) + "assets/" + name;
3}
4SDL_Surface* s = IMG_Load(asset("player.png").c_str());