Introduction For decades, the Simple DirectMedia Layer (SDL) has been the silent workhorse of cross-platform game development and multimedia applications. From indie darlings like Celeste to AAA titles and emulators like RetroArch, SDL provides a unified interface to handle windows, input, graphics, and audio across Windows, macOS, Linux, iOS, and Android. In early 2024, the long-awaited SDL3 was released, bringing modernized APIs, better GPU integration, and a cleaner, more predictable programming model. This essay provides a complete, runnable example of an SDL3 application and dissects every component, demonstrating why SDL3 represents a significant evolution from its predecessors. The Big Picture: What SDL3 Changes Before diving into code, it is crucial to understand SDL3’s philosophical shift. SDL2 relied heavily on SDL_Surface for software rendering and SDL_Texture for hardware-accelerated 2D. Initialization was monolithic, and many functions returned -1 on error. SDL3 simplifies this: initialization is now explicit and fine-grained, many obsolete functions have been removed, and the new GPU API (not used in this basic example) offers low-overhead access to Vulkan, Metal, and Direct3D 12. Furthermore, SDL3 adopts a more consistent naming convention (e.g., SDL_CreateWindow remains, but many event and input functions have been renamed for clarity). Our example will focus on creating a window, handling basic events, and rendering a simple animated shape using the modernized 2D renderer. The Complete Example: An Animated Bouncing Ball Below is a complete, working SDL3 program written in C. It opens an 800x600 window, creates a renderer, and animates a blue ball bouncing off the window’s edges. The code assumes SDL3 development libraries are installed (e.g., via vcpkg, Homebrew, or source compilation).
// Render SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); // black background SDL_RenderClear(renderer); // Draw a filled circle (using SDL_RenderFillRect would be simpler, but we approximate) // For a real circle, we'd use a texture, but SDL3's renderer still lacks native circle. // Let's draw a simple rectangle to keep the example focused. SDL_FRect ball_rect = { ball_x - BALL_RADIUS, ball_y - BALL_RADIUS, BALL_RADIUS * 2, BALL_RADIUS * 2 }; SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); // blue SDL_RenderFillRect(renderer, &ball_rect); // In SDL3, we call SDL_RenderPresent (same as SDL2) SDL_RenderPresent(renderer); // Frame rate control (optional: ~60 FPS) SDL_Delay(16); } sdl3 example
// 2. Create a window SDL_Window* window = SDL_CreateWindow("SDL3 Bouncing Ball", WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_RESIZABLE); if (!window) { SDL_Log("SDL_CreateWindow Error: %s", SDL_GetError()); SDL_Quit(); return 1; } Introduction For decades, the Simple DirectMedia Layer (SDL)