🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.8 KiB

  1. # Emscripten
  2. (This documentation is not very robust; we will update and expand this later.)
  3. ## A quick note about audio
  4. Modern web browsers will not permit web pages to produce sound before the
  5. user has interacted with them; this is for several reasons, not the least
  6. of which being that no one likes when a random browser tab suddenly starts
  7. making noise and the user has to scramble to figure out which and silence
  8. it.
  9. To solve this, most browsers will refuse to let a web app use the audio
  10. subsystem at all before the user has interacted with (clicked on) the page
  11. in a meaningful way. SDL-based apps also have to deal with this problem; if
  12. the user hasn't interacted with the page, SDL_OpenAudioDevice will fail.
  13. There are two reasonable ways to deal with this: if you are writing some
  14. sort of media player thing, where the user expects there to be a volume
  15. control when you mouseover the canvas, just default that control to a muted
  16. state; if the user clicks on the control to unmute it, on this first click,
  17. open the audio device. This allows the media to play at start, the user can
  18. reasonably opt-in to listening, and you never get access denied to the audio
  19. device.
  20. Many games do not have this sort of UI, and are more rigid about starting
  21. audio along with everything else at the start of the process. For these, your
  22. best bet is to write a little Javascript that puts up a "Click here to play!"
  23. UI, and upon the user clicking, remove that UI and then call the Emscripten
  24. app's main() function. As far as the application knows, the audio device was
  25. available to be opened as soon as the program started, and since this magic
  26. happens in a little Javascript, you don't have to change your C/C++ code at
  27. all to make it happen.
  28. Please see the discussion at https://github.com/libsdl-org/SDL/issues/6385
  29. for some Javascript code to steal for this approach.
  30. ## Building SDL/emscripten
  31. SDL currently requires at least Emscripten 2.0.32 to build. Newer versions
  32. are likely to work, as well.
  33. Build:
  34. $ mkdir build
  35. $ cd build
  36. $ emconfigure ../configure --host=asmjs-unknown-emscripten --disable-assembly --disable-threads --disable-cpuinfo CFLAGS="-O2"
  37. $ emmake make
  38. Or with cmake:
  39. $ mkdir build
  40. $ cd build
  41. $ emcmake cmake ..
  42. $ emmake make
  43. To build one of the tests:
  44. $ cd test/
  45. $ emcc -O2 --js-opts 0 -g4 testdraw2.c -I../include ../build/.libs/libSDL2.a ../build/libSDL2_test.a -o a.html
  46. Uses GLES2 renderer or software
  47. Some other SDL2 libraries can be easily built (assuming SDL2 is installed somewhere):
  48. SDL_mixer (http://www.libsdl.org/projects/SDL_mixer/):
  49. $ EMCONFIGURE_JS=1 emconfigure ../configure
  50. build as usual...
  51. SDL_gfx (http://cms.ferzkopp.net/index.php/software/13-sdl-gfx):
  52. $ EMCONFIGURE_JS=1 emconfigure ../configure --disable-mmx
  53. build as usual...