Porting an OpenGL application to the web

Emscripten is a tool which compiles C/C++ applications to Javascript, which can then be run inside a web page in a browser.  I have started to work on adding an OpenGL translation layer which is based on WebGL.  The goal of this project is to make it possible to compile OpenGL C/C++ applications into Javascript which uses WebGL to draw the 3D scenes.

My first demo is a port of the es2gears application to the web.  es2gears is an OpenGL ES 2.0 port of the well-known glxgears application.  You can see the web port of es2gears in action if you’re using a WebGL enabled browser (Firefox, Chrome or Opera Next).  For some extra fun, press the arrow keys as the gears are animating!

Screenshot of the es2gears application

This port has been automatically generated from this version of es2gears.  If you want to play with this locally, you can fork the emscripten repository.

A note about the demo: this is not supposed to be a performance benchmark of any kind.  My GLUT implementation uses the requestAnimationFrame API if available which means that your rendering speed should be capped at about 60FPS.  And that is what you would get if you compile es2gears directly into a native application as well.  But this application doesn’t push either the CPU or GPU to their limits, so it is only useful as a proof-of-concept, and should not be used in order to compare the graphics/Javascript performance of browsers!

I’m very excited about this project, and this is only the beginning.  If you’re interested in this work, watch my blog for further posts about future demos!

Tagged with: , ,
Posted in Blog
9 comments on “Porting an OpenGL application to the web
  1. [...] Akhgari: “The goal of this project is to make it possible to compile OpenGL C/C++ applications into Javascript which uses WebGL to [...]

  2. This would be an amazing tool!

    There is a project underway to provide an OpenGL fixed-function capability on top of WebGL . I wish I could remember the name of or find it now, but that may allow you to port a much wider range of C++ apps to JavaScript!

  3. Ratty says:

    Loaded it on a trunk build. Got:

    (canvas not available)

    :P

    Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0a1) Gecko/20120125 Firefox/12.0a1 SeaMonkey/2.9a1

  4. Ehsan Akhgari says:

    Please type about:support in your address bar to make sure that your graphics card driver supports WebGL.

  5. [...] 这个项目还是很令人激动的,它可以让开发者把以前开发的OpenGL桌面应用带到Web上重新焕发新生。不过现在这一领域需要做的工作还很多,如果你有兴趣,不妨联系Ehsan试试。 分享到: 更多 Posted in WebGL新闻. Bookmark the permalink. ← 索爱宣布将 Android 4.0 上的 WebGL 后端实现开源 [...]

  6. Dear E. Akhgari
    I beg you to forgive me for requesting yr answer to a question that may be a simple one. When reading yr “Porting an OpenGL application to the web” I became aware that it is possible to port an application from C/C++ to Javascript using yr Emscripten program. Some years ago I programmed a ship desing procedure in C++, but under the DOS operating system and I should like to port it to Javascript under Windows OS to allow showing it in the WEB.

    As my coding knowledge is rather low, before diving in the study of Emscripten I should like to know if it is feasible that porting in practical and reasonable terms for a non-geek programmer like me. That is the question that I dare to present to you.

    Many thanks in advance.

    Juan J. Azpiroz

  7. Ehsan Akhgari says:

    If your application can be compiled using clang, then you can compile it to Javascript using Emscripten.  The runtime library (libc for example) also needs to be reimplemented in Javascript.  A bunch of commonly used libraries are already implemented in Emscripten.

    But in order to run a DOS application you also need to implement other things such as the segmented memory model, interrupts, etc.  That is not going to be trivial, I’m afraid, but would definitely be interesting.

  8. [...] Akhgari has a neat blog post on automatically converting a native OpenGL application to run on the web via WebGL using [...]

  9. [...] Akhgari has a neat blog post on automatically converting a native OpenGL application to run on the web via WebGL using [...]

1 Pings/Trackbacks for "Porting an OpenGL application to the web"
  1. [...] Akhgari has a neat blog post on automatically converting a native OpenGL application to run on the web via WebGL using [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>