90% of all the apps and games on the MagicLeap One are created with Unity (and a few with Unreal). It’s therefore not a surprise that almost all information, tutorials and available examples are focused on those two Game Engines. I want to change this and start a small series of articles on how to create a game in C/C++ using just the C-API of Lumin OS.

Lumin Runtime API

Besides the support of Unity or Unreal there is also Magic Leap’s own engine called Lumin Runtime. It’s more or less a C++ wrapper around the pure C-API and a kind of application framework that simplifies creating an App in C++. Conceptually it’s very similar to SceneKit from Apple and uses similar to it also a Scene Graph approach. From my point of view it’s a great fast-starter but when it’s about port C++ from another platform or create something highly optimised and fast (like your own game engine), a better solution is to use directly the C-API, which gives you full access to the platform. That’s what we will do together in the upcoming articles!

Why YOU should use C/C++ or not!

Because we can ;) I'm just kidding, in fact there are good and real reasons to do so, but of course there are also some disadvantages going that way.

At first why you should use C/C++:

You have existing code from another platform

You really want to understand and learn the platform and API

You want to create a Landscape application (Currently not possible with Unity or Unreal)

You want use and/or learn how to use OpenGL in AR/VR

You want better understand how VR, AR and Spatial Computing works

And when you should absolutely not use C/C++:

You are more interested on the gameplay itself and not about the underlying technology

You want to finish a game or app in the shortest time possible: Go with Unity. It’s so much faster and easier to create an experience, especially when it's your yours first one

You have an existing Unity project you want to bring to the Magic Leap One

You hate linear algebra :)

Why I use C/C++?

Everyone who follows me on LinkedIn knows that I’m a big retro gaming fan and work in my free time purely in C/C++ and mainly with Pixel Art or Retro style 3D Graphics. Also I love the game machines from the 70’s and 80’s like the Atari 2600 or the Vectrex. I write on my own game engine and have even written some emulators to still play my favored games from my childhood. Of course all in C++ and C… And so when I first worked with the ML1, the idea was born to create a Vectrex emulator for it.

Unfortunately during my time at Magic Leap I was always to busy to do it and the idea is waiting since then in my always growing backlog of ideas, lol.

Until now!

Learn to really understand the platform and Lumin OS

As I wrote above, there is almost no info about C/C++ programming for the ML1. Even in the SDK you find just very basic C examples. I want to change this. Instead of writing now just the emulator I’ve decided to create besides some articles that describe this process and are hopefully also helpful for others in search for this kind of information.

What you will learn?

We will create a very basic game engine and even a simple 3D game. Besides that you learn how OpenGL is used to create the awesome spatial experience and the wow effect everyone has, when first time see and use it. And last but not least, you will learn and see that it’s not so difficult and different to any other 3D platform to create a game just in C/C++.

My personal Project: The Vectrex Emulator

At first i made just a proof of concept and ported the Vectrex emulator from macOS. This was done in around 2h. But of course still 2D. The goal was to get an idea how it maybe will look and also how it runs performance-wise. In the next step i refactored the display code from 2D to 3D which took me another 2h. This includes also a basic user input support using the controller on the Magic Leap One. But don’t get a wrong picture. It was just possible to do it in this short time because i know the C-API very well and also just focused on the very basic stuff. Also i always take care in all of my projects that i have a good level of abstraction between the different game/app modules which helps to port it seamless to almost any platform. In the next weeks I will bring it to a final app and hopefully also get all the license approvals to release it for free. My main intention was just that i can play this games for myself (which i already can), but i think it would be nice for anyone who has a device and is a retro fan like me :)

Early version video. I will update it as soon there is a better one available.

The next steps to a production release:

Improve the line shaders to improve fps

Better thread handling to improve stability and experience

Better user input controls

Real 3D experience for the emulated games

Professional UI and 3D Effects

Sound support

Remote downloads of emulated games

Companion App

The Tutorial

The Tutorial itself consists of three parts (at first) and it’s not about creating the Emulator. But actually it uses the same base code that I will cover in this three articles:

Part I:

- Install and setup the toolchain

- Create the main file and OpenGL boilerplate code

Part II:

- A basic Game Engine and Game Objects

- Display in 3D space using shaders

Part III:

- User Input handling with the ML Controller

- Simple game and working game play

Part IV (Bonus Chapter):

- Porting the Engine to the Oculus Quest

All of them will be available in the next weeks and on part I already work :)

Disclaimer:

All the information used in my tutorial are available for everyone in the public API. Also all the opinions are my own and not necessarily the same as those of my former employer Magic Leap.

Important: Please also don’t ask me anything about Magic Leap. I’m a passionate 3D Software Engineer and as such a big fan of the device, SDK and platform. I love to work on VR and AR in general and devices like the Magic Leap One or Hololens 2 are clearly some early ideas on what we can expect in the future to see. Don’t give a sh… on all the different press releases. Get a device by yourself, write code on it and start to become an idea of how the future of Apps and Games might look like. It’s at least a great investment in your personal education. I hope I can give some useful information with this tutorial and hopefully the following articles helps you to build your own and better opinion. In that sense: Happy coding!

Visit also my blog at rogerboesch.com where I write about VR&AR on Magic Leap One and Oculus Quest, but also on retro game development for the machines of the 80s like the Sinclair ZX Spectrum, Sinclair QL, Atari 2600 and many others.