“Hello World!” for Oculus Rift Development Kit 2 (DK2)

Update: This blog post discusses building a simple C++ app for the Oculus v0.5.0 beta SDK. An updated example which shows how to build a simple C++ console app for the production Oculus Rift CV1/DK2 v1.3.2 SDK can be found here.

This post walks through the basics of building a simple C++ app for the Oculus Rift Development Kit 2 (DK2).  Setup of the development environment is covered first, with the coding of a simple app which reads the device’s sensors and outputs their state following after.

We’re working with the Oculus Rift 0.5.0 SDK for this example and a DK2 device. Everything posted in here is subject to change as the Oculus API matures (that’s no fault of Oculus — we were all told we’re getting a work-in-progress developer kit, and that’s what’s been delivered), so please do let me know if these notes no longer reflect reality for a developer new to the device.

Oculus DK2 Dev Environment Setup

If you’ve not already installed the Oculus Rift SDK, you’ll want to do so now. It is also assumed for Oculus development that the DirectX SDK and Windows SDK are already installed on your computer. We won’t need those SDKs for the initial ‘Hello World!’ completed here but will definitely need them later, so best to fetch those before starting to code.

The DirectX SDK can be retrieved from here:


And the Windows 8.x SDK (which works fine for Windows 7) from here:


It turns out that the DirectX SDK installer can conflict with the Microsoft Visual C++ 2010 Redistributable, resulting in a cryptic “Error Code: S1023” installation failure. If that happens to you (as it did to me), this StackOverflow post will sort you out.

Microsoft Visual Studio (VS2013) is used as the development environment for the examples shown here. To test that environment after all SDKs are installed (and give us a VS2013 project into which we’ll put our example code) we’ll start out with a traditional ‘Hello World!’ program.

Using the VS2013 File > New > Project… wizard to create a new console app (being sure to turn off the “Precompiled header” checkbox option), we’ll pop into the editor:

and then use the VS2013 Build > Build Solution menu option to create an executable.

With “Hello World!” output to the console when running that exe, we’ve confirmed our development environment is good to go.  Onwards to the DK2!

The Oculus developer documentation is a bit vague on the libraries needed for the basics, and the code examples included with the SDK cover a good amount of DirectX and other extra bits we’re not needing just yet.  Checking the Oculus developer forums, the latest news on libraries tells us that the only ones needed for the linker are:

libovr.lib (libovrd.lib in debug)

We’re just working with the Oculus SDK for now, so the libovr.lib and libovrd.lib alone will be sufficient.

Continuing with our simple ‘Hello World!’ project environment, we’ll add in the libovr.lib and libovrd.lib libraries through the VS2013 project’s properties (right-click the project for the Properties dialog selection) under Linker > Input > Additional Dependencies, adding in the file and path for those two .lib files. On my own system, those were under:


Your own path, of course, will depend upon the installation location of your Oculus SDK.

Next, we’ll include the Oculus SDK.

In VS2013 again, under the project’s properties, Configuration Properties > C/C++ > Additional Include Directories options, we’ll set the path to the SDK’s LibOVR Include, which could be found on my own system at:


Our development environment is now ready to create our basic Oculus program.

Starting Oculus DK2 Coding

To get a feel for how an Oculus program works, I opened up the Tiny Room sample code included with the SDK and…


It’s been a while since I last worked in C++ and that sample code felt more unfamiliar than I was comfortable with. Before going any further, it was back to school for me.

The full MIT Open Courseware introduction to C++ class is available online, and stepping away from things to read the full lecture notes and coding up the assignment basics provided just the refresher I needed. If it’s been a while since you’ve coded in C++, I’d recommend completing that course yourself to scrape the rust off your knowledge.

With that done, back to Oculus.

The Oculus Developers Guide provides an example initialization of the device through this snippet:

Let’s put that into working code.

Using the above example for reference, we’ll confirm we can connect to the DK2 by initializing the device and fetching its product name and firmware version.  That’s accomplished with this bit of code:

With the DK2 turned on (look for the orange light on the headset), running the exe compiled from the above gives us the device’s attributes output to console:

So far so good. Now we’ll try reading some sensor data.

Referencing the Oculus Developer Guide again, under the Head Tracking and Sensors section we can see how to start up the DK2’s sensor and read in the tracking state. Putting all that into code with a loop to push out the results gives us:

With the output to console being:

Success!  The DK2’s sensors are being read and updating to reflect the device’s orientation.  ‘Hello World!’ is accomplished.

Now, to get my head around the Tiny World sample code…

9 thoughts on ““Hello World!” for Oculus Rift Development Kit 2 (DK2)”

    1. charlesodale Post Author

      Hi Eason,

      Yes, the Oculus SDK has undergone quite a few changes since the v0.5.0 used in my original blog post, and you’ll be needing to adjust your code to accommodate that. A quick check of the latest SDK’s documentation (the publicly available version of which is v0.8.0 at this time) should show you exactly what is needed to correct for the errors shown in your VisualStudio output.

      I’ll be sure to post an updated ‘hello world’ example for reference once I have the final Oculus v1.0.0 SDK in-hand.

  1. shai

    In sdk version 0.8 the procedure has changed:

    here is a similar code that worked for me:


    using namespace std;

    int main()
    ovrResult result = ovr_Initialize(nullptr);
    if (OVR_FAILURE(result))
    return 0;

    ovrSession session;
    ovrGraphicsLuid luid;
    result = ovr_Create(&session, &luid);
    if (OVR_FAILURE(result))
    return 0;

    ovrHmdDesc desc = ovr_GetHmdDesc(session);
    ovrSizei resolution = desc.Resolution;

    cout << desc.ProductName << endl;


    return 0;

    1. charlesodale Post Author

      Thanks for that, Shai.

      Yes, the Oculus SDK has been changing continuously leading up to the v1.0.0 Oculus SDK’s release. Code has required changing about every ten weeks or so as those new versions come out, but that chase should come to an end once the Oculus SDK is out of beta.

      I’ll be sure to post an update once I have the 1.0.0 Oculus SDK in-hand. Until then, the error output in Visual Studio should lead developers in the right direction to correct for the various changes brought about by later SDKs, and your own example should help out quite a bit for that. Thank you for posting it!

    1. charlesodale Post Author

      Hi Eric,

      Unfortunately, Oculus has removed the ability to directly poll the raw sensor data of the HMD. Those x,y,z details are no longer available in the 1.3 SDK.

Comments are closed.