A libretro frontend library for SDL3.
Features
- Header-only C99 library
- Audio via
SDL_AudioStream with dynamic rate control
- Input with gamepad, keyboard, mouse, lightgun, or pointer
- Save states and SRAM
- Memory access and memory-map descriptors (cheats, debuggers, RAM watching)
- Core options
- Fast-forward and slow-motion
- Rewind with delta compression
- Rumble
- On-screen display messages
Usage
Define SDL_LIBRETRO_IMPLEMENTATION in exactly one .c file before including the header:
#define SDL_LIBRETRO_IMPLEMENTATION
SDL_libretro - SDL3 libretro frontend library.
All other files include SDL_libretro.h normally without the define.
Quickstart
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD);
SDL_Window* window = SDL_CreateWindow("SDL_libretro", 800, 600, SDL_WINDOW_RESIZABLE);
SDL_Renderer* renderer = SDL_CreateRenderer(window, NULL);
SDL_Event event;
while (SDL_PollEvent(&event)) {
}
SDL_Libretro_Update(lr);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
bool SDL_Libretro_Render(SDL_Renderer *renderer, SDL_Libretro *lr, const SDL_FRect *dstRect)
Render the libretro context in the given renderer.
bool SDL_Libretro_LoadCore(SDL_Libretro *lr, const char *corePath)
Loads a libretro core.
bool SDL_Libretro_LoadGame(SDL_Libretro *lr, const char *gamePath)
Loads a game at the given path.
bool SDL_Libretro_ShouldQuit(const SDL_Libretro *lr)
Indicates whether or not the core has requested to shutdown.
void SDL_Libretro_Destroy(SDL_Libretro *lr)
Destroys the given libretro context.
SDL_Libretro * SDL_Libretro_Create(void)
Builds a libretro context.
void SDL_Libretro_HandleEvent(SDL_Libretro *lr, const SDL_Event *event)
Call this function within the SDL_PollEvent() loop to ensure libretro knows of important events.
Build
git clone --recurse-submodules https://github.com/RobLoach/SDL_libretro.git
cd SDL_libretro
mkdir build && cd build
cmake ..
cmake --build .
SDL3 is fetched automatically via CMake FetchContent if not already installed on the system.
Emscripten
With the Emscripten SDK activated, configure through emcmake:
emcmake cmake -B build-web
cmake --build build-web
Configuration
Use macros before SDL_LIBRETRO_IMPLEMENTATION to change how SDL_Libretro behaves.
SDL_LIBRETRO_ENABLE_REWIND_DELTA: Enable the XOR delta between rewind frames to reduce memory at the expense of performance
Dependencies
License
[zlib/libpng](LICENSE)