Porting Urho3D to HTML5?

394 views
Skip to first unread message

Sinan - info@sinsoft.com

unread,
Oct 18, 2013, 6:44:33 PM10/18/13
to urh...@googlegroups.com
Hi, I'd like to have one forum thread discussing HTML5 and the possibility of porting Urho3D to HTML5.

From my current research, since Urho3D uses SDL 2.0, it should technically be possible to port Urho3D to HTML5 using Emscripten:



So the idea is to compile all of Urho3D into 'LLVM bitcode', and use the Emscripten compiler to convert that 'LLVM bitcode' into 'JavaScript bytecode', which you would then embed as an HTML5 object inside an HTML5 project.

So you can use Urho3D for native apps on Mobile, however on PC/Linux/Mac you would use HTML5 and allow the user to use the content from a web browser. There are issues of course, i.e. currently SDL 2.0 would not compile as is to 'LLVM bitcode', however I think the Emscripten team is working on it.

For a lot of projects, HTML5 does make sense on the desktop. So you can use the horsepower of mobile by creating a native app, but desktop should have the horse power to run the same app from the web browser (or at least 60-70% performance of the mobile version). -- It depends on the app of course

Sinan - info@sinsoft.com

unread,
Oct 18, 2013, 7:23:21 PM10/18/13
to urh...@googlegroups.com
Sorry, correction:

You might indeed be able to compile SDL 2.0 or Urho3D into 'LLVM bitcode', but the Emscripten compiler would not be able to necessarily convert it into JavaScript bytecode. But like I mention, the Emscripten team is working on it.

Alex Fuller

unread,
Oct 18, 2013, 9:34:01 PM10/18/13
to urh...@googlegroups.com
Hi Sinan,

Last time I used emscripten with Urho3D, emscripten supplies its own SDL API as part of the toolchain, but I think at the time Urho had a few custom changes to SDL so it didn't seem to work, but I didn't get the time to investigate too much. This was a much earlier SVN release as well before the revamped building system it has now.

From memory I also needed to 'massage' some files to work for the kNet stack as the emscripten toolchain had badly formatted headers for sockets, which I'd assume wraps to HTML5's equivalent under the hood somehow, and bypass the little/big endian conversions as the HTML5 sockets were big endian by default, but I forget now.

At the end of the day it did compile but I had no clue on how to debug it from then onwards, I just had a really damn massive javascript file that got gzipped and a blank screen in chrome. :)

Best of luck if you can get it to work Sinan!
-Alex

Chris Friesen

unread,
Oct 18, 2013, 10:07:08 PM10/18/13
to urh...@googlegroups.com
i don't know how to debug webgl as i am just a dumb web guy but javascript engines use something called sourcemaps to map javascript back to the original language.

https://github.com/kripken/emscripten/pull/1267

it looks like basic sourcemaps were implimented.  i can only image how goofy the coersion would be.

And indeed good luck Sinan.

Lasse Öörni

unread,
Oct 19, 2013, 6:36:34 AM10/19/13
to urh...@googlegroups.com
I believe this should be perfectly possible as engines like Unreal 3, Unigine and Nebula Device 3 have already been ported to emscripten, just quite a bit of work and with some notable caveats:

- Angelscript native bindings couldn't be used, so either the bindings would also need generic calling convention (which is a lot of ugly glue code) or Angelscript scripting should be simply dropped for HTML5. It probably makes sense.. C++ to Javascript is slow enough without also running a virtual machine within Javascript :)

- All SDL-interfacing code needs to be #ifdef:ed in emscripten mode and use only the SDL API which emscripten supports, which is more like SDL 1.2. It does not make sense to actually try to compile SDL2 with emscripten.

And to make it clear, this is not currently on Urho3D roadmap, ie. we very likely won't be doing this. But if you can make it work and want to contribute it back, that would be awesome.

Sinan - info@sinsoft.com

unread,
Oct 19, 2013, 11:36:13 AM10/19/13
to urh...@googlegroups.com
Thanks for all the replies.

My dev environment is Linux and Emscripten doesn't have an SDK for Linux yet. So I would have to compile it manually for Linux if I were to try this.

It's not a top priority, I'll give it a shot, but it will be on a long term roadmap for me (i.e. like trying to get it done over the next 6 months).

It looks complicated, and the loss of AngelScript is not a good thing for me, as that eliminates the multi-platform aspect of the game engine. So if AngelScript has to be dropped, then it's not worth it for me.

But I definitely think this is the way forward for some projects in the future. That is, on PC/Linux/Mac, HTML5 should be used. 

But after doing more research, and after your replies, my question has been answered:

It's definitely should be doable, but a lot of work is involved.

If I do end up working on it, and if I get it working, I will most definitely contribute the code back.

Alex Fuller

unread,
Oct 24, 2013, 12:49:32 AM10/24/13
to urh...@googlegroups.com
Just realised I sent this directly to Sinan and not the mailing list proper, sorry:

Hi Sinan

Building the toolchain for Linux I didn't find to be difficult but I can't remember, I think it was trickier to find a recent llvm and clang for Ubuntu 12.04 in some PPA.

Lasse: I think emscripten has SDL2.0's API out of the box actually, I just skipped building it and made it use its own headers and linked it to its lib.

It would be interesting to see an angelscript frontend to llvm that could convert to llvm's IR. I think just writing in C++ would be the way to go here and I think Unreal came to the same conclusion (and perhaps why Unreal Engine 4 just supports kismet nodes and hot compiles/reloads of C++ code).

Sinan - info@sinsoft.com

unread,
Nov 19, 2013, 6:23:33 PM11/19/13
to urh...@googlegroups.com
Just to give an update.

I have no plans to work on this anymore (i.e. port Urho3D to HTML5) since I decided to build a custom 2D HTML5 engine.

A 3D engine with WebGL is also a possible side project, since HTML5 can handle the same tasks that SDL can, like windows creation, input, and audio. So prototyping with WebGL is pretty fast (I would think) and there are libraries like threejs, etc. Although it is not fair to compare the two, since for example HTML5 audio needs extra work to make it work cross platform where SDL does a better job.

However the next project is in 2D and will require a 2D engine with Box2D (box2d.js) integration.
Reply all
Reply to author
Forward
0 new messages