Using Shared WinRT C++ Physics Engines in Your WinJS game

Currently there are no Physics Engines that will drop into WinRT and work, but bear in mind that WInRT is used when you need language projection.  That is: You write the code in C++/CX and consume in JavaScript or C# or VB or even C++.  Or C# and consume in the other languages, VB is the same, but JavaScript can only consume.

With respect to existing game libraries like UDK or Autodesk ScaleForm, these C++ libraries can be used with a little more work then I wanted to do, consumed through WinRT and then projected into JavaScript. 

Now, it is likely once I post this blog, there will suddenly be 10 or 15 Physics Engines modified to work with WinRT, but for now, there aren’t any that have easily discovered documentation. 

So what is Windows Run Time?  Windows Run Time is a strict protocol that requires that the components have very specific types of interfaces that are different then the previous COM objects.   Unlike COM, WinRT components is strictly limited to code that can be compiled into winmd files for consumption by your application that requires language projection. 

So, in this article we will investigate:

  • Using WinRT with JavaScript, (a very simple example)
  • What is Windows Run Time and DirectX
  • Static Libraries and WinRT
  • WinRT C++ and Current Physics/Game Engines

Using a custom WinRT component with JavaScript

If there were physics engines ready to use with WinRT without a large number of steps, we would still have to utilize this sample to get you started.  There are complicated samples on how to use WinRT, in this case I am going to keep it very simple.  If you know how to program with C++/CX and you know JavaScript, then this will be enough to get you going. If you are trying to tie everything together and get an app produced, then this is a simple way to decide if you want to use C++ in your JavaScript.  Keep in mind that you can use Windows Run Time without using C++ or create a WinRT Component.

Create the C++ elements. see the blog post, the WinRT CPP Component can be used with the JavaScript:

Then follow the instructions in this brief blog and you will have consumed a WinRT component with JavaScript (as well as XAML):

One of the useful but more complicated WinRT sample that project into JavaScript:

What is Windows Run Time?

Windows Run Time is a foundation for building the Windows 8 Modern UI interface, it is a library as well as a way for you to create a customer interface.  At this time you are likely better off reusing the Box2D code while making sure to include that you used it in an about statement.  There is the Windows Runtime Core exposes the kernel, then on top of that there is the APIs and Metadata.  For this article there are the important component of Language Projections.  To be able to implement the Language Projections there are restrictions on the JavaScript side, but not on the access to the Windows Core.  This means that the interfaces are different the COM interfaces.

When you use C++/CX in Windows Run Time components, you can write components that won’t run on the ARM, but you will be able to work directly with the CPU and GPU, whereas with C# and VB you are required to use .NET Managed Code.

In documentation and websites, sometimes it appears that Windows Run Time are programs that only run on the ARM, that isn’t the case, if a program runs on the ARM, it will in most cases, run on an Intel device.  Windows Run Time is a Library and a way for you to create customized code in one language such as C++, C# or VB and consume that code in the same language or another language including JavaScript.  If the component is created in C++ you have close access to the CPU and GPU or .NET Managed Code, if it is created using Visual Basic or C# then you are using .NET Managed Code.  The WinRT is sealed and can only be used by the solution it is contained in, with the exception of a shared contract.

For a video that illustrates the general idea of what WinRT is see:


WinRT with Direct2 and Direct3

You can use Direct2 and Direct3 with JavaScript.  There are a number of samples that utilize this technology, but the Direct2 and Direct3 are not WinRT based.  You use Direct2 and Direct3

As to where is the “x”?  If you don’t know if it is Direct2 (2D) or Direct3 (3D) then you use the x as in DirectX

For an excellent presentation on 2D Graphics with Direct2D see (it is somewhat out of date in specifics with the code but up to date generally):

Using WinRT in a Static Libraries

You can create static libraries and then include the WinRT components in them, this way you can generate a number of WinRT components that can be combined into a Static Library, see  Static libraries (C++/CX).   In this manner, you can now combine WinRT components..


Once you combine the WinRT components together into a Static Library you will need to modify the Metro app you are projecting into.

If you need to find out more about Static Libraries this link will help out:


WinRT C++ and Current Physics/Game engines

As far as I can tell, there are no WinRT or Static Libraries that are made up of WinRT components that can be used in JavaScript or other languages at this time.  C++ libraries can be consumed by WinRT for language projection, so even if these libraries are not directly consumable, it is still possible with a bit of effort to consume them.

There are a number of engines that you might want to take a look at.  For instance Box2D, an open source physics engine and it would be possible to modify it to work in WinRT.  If you are on a 30 Day approach to building a game and getting into the store, then use Construct2 from, which will compile into a Visual Studio Project but aren’t quite ready for the Windows Store.  The Scirra Construct2 will implement a Windows 8 like shell but doesn’t have the snap, fill screens, however, that is fairly easy to overcome.

Here are the game engines that will likely be there soon, these are likely documented elsewhere, but I researched them for this article and just have to include the documentation.  For a video that discusses how to consume a non-WinRT C++ Code set see: Building Windows Runtime Components with C++.


Box2D is a dandy little open source physics engine, and it is used in Physics Helper, Construct2 by and so forth.  As it stands in the open source world, it will not work inside of a WinRT form of COM.  Why is this?  WinRT components created by developers are by designed forced to use the Windows Run Time Libraries, for instance by default WinRT links to a single library, the runtimeobject.lib.  If you wanted to include another library directly, such as the Windowscodecs.lib, then you would add it on the line Additional Dependencies.  In the near future, but not on 8/31/2012, there are no physics engines that will work in the WinRT system.



The UDK 3 is shown working on Windows Run Time, which in the case of the video is referring to the ability to work on Intel and ARM devices, but I was not able to find the library on the UDK site.  The process of “language” projection is not clear and considering the Epic capabilities and presence in the game industry, they are able to manipulate the technology as they see fit.  Since the announcement was on 8/29/2012, it might take a few days to get the documentation out there.  Feel free to leave a comment if you find it.  I will be posting the information if I find it.

For the Unreal Engine 3 article see:, it appears that licensees are able to access the Windows RT code at, but I was unable to locate the documentation.

Autodesk Scaleform 4.1 now supports Windows Metro

The Autodesk Scaleform 4.1 states that it does support Windows 8 Metro in the 4.1 version, but the downloaded files did not show how to do so, and the DirectX version is version 9, if you have time you might want to take a look, but it was just frustrating.  Tale a look at ScaleForm at:, you can download the tool for non-commercial use. 


In this article you have been given guidance on how to use WinRT and why to use WinRT.  At this time, it is possible to use existing game engines with WinRT, but the amount of effort might be larger then you want for the initial launch.  There are tools like Construct2 by that can get you up and running quickly.  This type of implementation over time is more like a prototyping approach then an actual final production phase, but it can get feedback from the audience on the Microsoft Windows Store.

Comments (2)

  1. David says:

    What about the JS Box2D port?

  2. Surf4Fun says:


    Good point about the JS Box2D port. I didn't know about it, but even if I had, the blog's point was about consuming Game Engines with WinRT.

    On the other hand, this is definitely the way to go.

    Thank you David!

Skip to main content