Platform backends: compile-time selection

raylib supports many targets by swapping the platform implementation textually included into rcore.c. CMake/Makefile/Zig must agree on the same PLATFORM_* preprocessor define.

Platform picker

Tap a backend to see its define, source file, and notes.

Define:

File:

Preprocessor dispatch in rcore.c

#if defined(PLATFORM_DESKTOP)
    #define PLATFORM_DESKTOP_GLFW
#endif

#if defined(PLATFORM_DESKTOP_GLFW)
    #include "platforms/rcore_desktop_glfw.c"
#elif defined(PLATFORM_DESKTOP_SDL)
    #include "platforms/rcore_desktop_sdl.c"
#elif defined(PLATFORM_DRM)
    #include "platforms/rcore_drm.c"
// ... etc
#endif

rcore.c L509–535

Platform .c files are not separate translation units — they share CORE and static platform state with rcore.c (unity-build style).

Platform contract — required functions
  • int InitPlatform(void) / void ClosePlatform(void)
  • void SwapScreenBuffer(void)
  • void PollInputEvents(void)
  • bool WindowShouldClose(void)
  • Window/monitor/cursor/clipboard helpers

Template: platforms/rcore_template.c

GLFW InitPlatform (desktop default)
  1. glfwInit() with RL_* alloc wrappers
  2. Window hints from CORE.Window.flags (MSAA, resizable, HiDPI…)
  3. OpenGL version from rlGetVersion()
  4. glfwCreateWindow, glfwMakeContextCurrent
  5. rlLoadExtensions(glfwGetProcAddress)
  6. Register input/window callbacks → update CORE.Input

rcore_desktop_glfw.c — InitPlatform

rglfw.c — vendored GLFW

When not using system GLFW, rglfw.c compiles all external/glfw/src/*.c into one object. CMake uses GlfwImport.cmake; Makefile links rglfw.o separately.

CMake PLATFORM mapping
CMake -DPLATFORMC define
DesktopPLATFORM_DESKTOP → GLFW
SDLPLATFORM_DESKTOP_SDL
RGFWPLATFORM_DESKTOP_RGFW
WebPLATFORM_WEB
DRMPLATFORM_DRM
AndroidPLATFORM_ANDROID
MemoryPLATFORM_MEMORY