Search code examples
c++djangoqtsdlsdl-2

Using SDL for a web application


I'm currently working on an SDL 2 application (C++) and I have a question. As the title suggests i'm attempting to use SDL as a web app. I wanted to know what the best way to go about this would be. I've put some research into this and the avenues to take would either be:

  • Interfacing with python
  • Using Wt as a toolkit and layering SDL 2 on top of it.
  • Using QT creator and layering SDL 2 on top of it.

Clearly there must be other ways to do this, but my primary concern is the fact that SDL 2 expects some form of a window (SDL_Window) and renderer (SDL_Renderer), will my options help me overcome the hurdle? Or would I have to directly code SDL 2 into python and attempt to use that along with Django (or some other form of web app API) to do as I need?

P.S I'm not looking to get into any other API's other than SDL/Opengl(If I must). I'd like to know if it's possible to get SDL working on a web application.


Solution

  • It is possible using Emscripten

    I've succesfully compiled many SDL2+OpenGL projects to JS

    Read this page first: http://kripken.github.io/emscripten-site/docs/porting/multimedia_and_graphics/OpenGL-support.html

    The default SDL version is 1.2. To use SDL2, you have to explicitly tell it to the compiler like this:

    -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS="['png']" 
    

    If you have to use OpenGL 3 features (and/or GLSL newer than 1.0), use this parameter too (requires WebGL 2):

    -s USE_WEBGL2=1
    

    In the code you have to replace the while(!quit){ ... } main loop with an emscripten_set_main_loop call.