SDL Mixer Version 3 Released
The SDL team recently released version 3 of the SDL_mixer library. Nearly the full suite of SDL libraries now have a version 3 release tag, with just SDL_net remaining.
Over the past few months, I put some work into an SDL2 + Emscripten sample project. It was intended to act as a reference project for how to build an SDL2 application using CMake that is able to target both a desktop and WebAssembly build.
With the release of SDL_mixer version 3, I figure that most new game projects going forward are likely going to target the full SDL version 3 library: SDL, SDL_image, SDL_ttf, and SDL_mixer.
Will Emscripten Provide Built-In SDL3 Support?
This is the main question that I've been pondering. A dedicated implementation for SDL version 2 was provided by the Emscripten team, to help make it easier to compile SDL-based games into WebAssembly. Since then, the SDL team has worked on supporting Emscripten natively throughout their library suite. So it's possible that the Emscripten team won't see the need to provide built-in SDL3 support.
Building SDL in a CMake Emscripten Project
Building an SDL2 application with CMake is actually quite convenient once you know the compiler and linker flags to pass in for your target. The Emscripten section of my CMake + SDL2 + Emscripten project's build, found in my cmake-testing-grounds repository looked like the following:
target_compile_options(
Sdl2EmscriptenExample PRIVATE
"-sUSE_SDL=2"
"-sUSE_SDL_IMAGE=2"
"-sUSE_SDL_MIXER=2"
"-sUSE_SDL_TTF=2"
"-sSDL2_IMAGE_FORMATS=[\"png\",\"jpg\"]"
"-sSDL2_MIXER_FORMATS=[\"ogg\"]"
)
target_link_options(
Sdl2EmscriptenExample PRIVATE
"-sUSE_SDL=2"
"-sUSE_SDL_IMAGE=2"
"-sUSE_SDL_MIXER=2"
"-sUSE_SDL_TTF=2"
"-sSDL2_IMAGE_FORMATS=[\"png\",\"jpg\"]"
"-sSDL2_MIXER_FORMATS=[\"ogg\"]"
"--preload-file" "${CMAKE_SOURCE_DIR}/src/resources@resources"
"-sALLOW_MEMORY_GROWTH=1"
"-sASSERTIONS=1"
"-sFORCE_FILESYSTEM=1"
)
You didn't need to build SDL2 into your application for your Emscripten build.
With SDL3, this changes. Your desktop build and Emscripten build alike will both need to build SDL3 and link to it. Depending on how you look at it, this might actually be more convenient, because your build no longer has if(EMSCRIPTEN) blocks if you're targeting both environments. You'll just link directly to the SDL3 libraries, whether you're targeting desktop, mobile, or Emscripten.
What I'm a little less certain about is how this will affect how you organize your game loop, or what sort of gotcha's there might be using each of the SDL modules. I plan to create a separate CMake + SDL3 + Emscripten project that will explore these questions, and provide a reference project for SDL version 3...
I'm a little too close to the finish line on my jigsaw puzzle game to tackle that anytime soon. But as soon as I have an initial release for my game, I plan to circle back to this. I may even take on the task of upgrading the game from SDL2 to SDL3, which could be an interesting exercise on its own...