Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have read that on desktop OpenGL + SDL is a great way to learn. In looking at WebGL I couldn't find a Web version of SDL. On their site I see bindings for all sorts of languages, but no JavaScript. It seems obvious that this gives an answer of 'no' to my question, but I also came upon code snips while googling around that seemed to be doing it. Whatever the missing piece is I'm not getting it...

share|improve this question
1  
you can use it native client developers.google.com/native-client/community/porting/SDLgames –  SRN Feb 8 '13 at 12:25

3 Answers 3

up vote 3 down vote accepted

When used with OpenGL SDL is responsible for opening a window, creating an opengl context, handling events, etc. The drawing part is OpenGL responsibility.

In a browser, you already have a window, ways to handle events and a way to get a context, SDL would not be very helpful in this scenario.

Although, mimicking the SDL API in javascript might be helpful for those familiar with it, I couldn't find anything for a webgl game. If you are interested in using javascript for developing SDL apllications, there is node-sdl, though.

share|improve this answer

The literal answer is actually yes because the Emscripten project, for compiling C++ applications to Javascript for running in browsers, provides an implementation: "libc and stdlibc++ support is very good. SDL support is sufficient to run quite a lot of code. OpenGL support is in very good shape for OpenGL ES 2.0-type code, and even some other types," in https://github.com/kripken/emscripten/wiki/FAQ

However that is only useful for compiling C / C++ written SDL using apps to browsers -- not at all for developing in Javascript for browsers to begin with, for all the reasons given in previous answers. Just a note for the record :) And this is what allows Quake and Unreal and such to be compiled to run with webgl in browsers..

share|improve this answer

I think it's highly unlikely that SDL + WebGL is a useful combination.

SDL is a C library, and WebGL can only be used with Javascript. While it is possible to compile C code into Javascript, none of the underlying libraries used by SDL are available from inside a web browser.

Also the level of abstraction is fundamentally different: SDL was originally conceived as a small layer to allow native C programs to gain access to Framebuffers in an OS independent and convenient way. This allows games which use software rendering to be written more easily.

On the other hand, WebGL is for Javascript in a browser rendering into a canvas. This is already implementation-agnostic.

You're probably better off using something like Three.js if you are targetting a web browser (NB: do not consider this a recommendation)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.