HTML and CSS Reference
HTML5 Games in C++ with Emscripten
Chad Austin, Senior Technical Director, IMVU
in web browsers, I would have thought you were crazy. Since then, software has shifted from retail stores and optical
discs to online app stores and web applications. Internet users have become increasingly security-conscious, and
The Web is the ultimate platform. It is secure: applications have no direct access to the local machine. It is
seamless: users merely have to click a link to experience your game or web site. It is royalty-free: if you can host a web
page, you can distribute a web app. It is capable: with the advent of HTML5 and WebGL, web applications have access
to an increasing set of functionality, such as gamepads, full screen display, and local storage. And now, the web is fast
too: with the advent of technologies like Mozilla's asm.js and Google's Portable Native Client, web applications can
approach native performance.
a portable bytecode was a better direction for the Web. However, the future is created by the people who invent it.
Alon Zakai, with a vision in his head and persistence in his actions, created Emscripten as an open source project.
Eventually Mozilla hired him and gave him funding to continue full-time development on Emscripten. Emscripten
has since been proven viable and even Epic's Unreal Engine 3 has been ported to HTML5 with it. While I would have
has strong survival genes: Emscripten-generated code runs on all recent browsers, including Internet Explorer 10,
and Native Client is a far more complicated piece of technology.
In this chapter, I will describe how Emscripten works, why it's fast, what's possible, and then I will demonstrate
what it's like to port an existing C++ game to the browser. Being new, Emscripten is rough around the edges, but I will
cover the common problems you may run into and how to address them.
What is Emscripten?
Emscripten relies heavily on LLVM, a set of open source compiler tools. The LLVM project provides both Clang,
a compiler from C++ to platform-independent LLVM instructions (known as LLVM IR), and a set of platform-
independent optimization passes and tools. The LLVM project is hosted at http://llvm.org/ . With the help of