C++ "Hello World!" for Oculus Rift CV1 / DK2 SDK 1.3.0

As promised, here's a sequel post for creating a simple 'Hello World' console app in C++ for your Oculus Rift, this time covering the final production 1.3.0/1.3.2 Oculus SDK for CV1 and DK2 devices.

If you enjoyed developing software on the Oculus DK2, I have some bad news for you.

If you've not yet set up your environment for C++ development, the earlier Oculus Hello World post for the v0.5.0 runtime will give you the steps you're wanting to follow for that.

The latest Oculus SDK can be retrieved from here:

https://developer.oculus.com/downloads/

With the Oculus v1.3.2 runtime provided through the general Oculus setup program, here:

https://www.oculus.com/en-us/setup/

For the code itself, this simple program:

#include <iostream>
#include <iomanip>
#include <OVR_CAPI.h>
#include <thread>

#define COLW setw(15)

using namespace std;

int main()
{   // Initialize our session with the Oculus HMD.
    if (ovr_Initialize(nullptr) == ovrSuccess)
    {
        ovrSession session = nullptr;
        ovrGraphicsLuid luid;
        ovrResult result = ovr_Create(&session, &luid);

        if (result == ovrSuccess)
        {   // Then we're connected to an HMD!

            // Let's take a look at some orientation data.
            ovrTrackingState ts;

            while (true)
            {
                ts = ovr_GetTrackingState(session, 0, true);

                ovrPoseStatef tempHeadPose = ts.HeadPose;
                ovrPosef tempPose = tempHeadPose.ThePose;
                ovrQuatf tempOrient = tempPose.Orientation;

                cout << "Orientation (x,y,z):  " << COLW << tempOrient.x << ","
                     << COLW << tempOrient.y << "," << COLW << tempOrient.z
                     << endl;

                // Wait a bit to let us actually read stuff.
                std::this_thread::sleep_for(std::chrono::milliseconds(100));
            }

            ovr_Destroy(session);
        }

        ovr_Shutdown();
        // If we've fallen through to this point, the HMD is no longer
        // connected.
    }

    return 0;
}

Will connect to your Oculus HMD (Head Mounted Display) using the Oculus 1.3.2 runtime, read the device's orientation and output that data to console, with the code structure essentially the same as for the previous v0.5.0 SDK example

The earlier Oculus 'Hello World' example connected directly to the device's raw sensor data, but that option is no longer being provided under the Oculus 1.3.2 SDK. Unfortunately, that's not the only limitation presented by the Production Oculus SDK.

If you enjoyed writing C++ programs for the Oculus DK2, I have some bad news for you.

The Bad News for C++ Development on Oculus

When starting the simple "Hello World" example provided above on your Oculus CV1 or DK2, you'll notice two things.

First, the Oculus Store opens:

oculus_store

Yes, that happens every time you connect to the Oculus, no matter how trivial your program is.

No, you cannot do anything to turn that off.

It's not an exaggeration to call this horrible: It's as if Logitech or Microsoft had set up a store to be shown on your screen whenever you plugged in your mouse and provided no means at all to be able to dismiss it.

It gets worse.

The second thing you'll notice is that your HMD displays a Health and Safety warning which occupies your Oculus screen until dismissed. You can dismiss that either by positioning a cursor on-screen for a few moments or clicking the "A" button on your Oculus XBox controller.

If you're developing software, that rhythm gets really old, really fast and, no, Oculus provides no mechanism for bypassing it.

Finally, after dismissing that warning, your HMD will display a "Please Wait..." message and, if you're looking to develop a simple console app to run alongside your Oculus, that's where things stop.

The Really Bad News for C++ Development on Oculus

...general C++ hacking with the Oculus Rift seems to have come to an end

Unfortunately, it appears the Oculus v1.3.2 runtime no longer allows console applications to run in parallel with apps on the HMD.

Even the trivial program shown above cannot run at the same time as an Oculus game or movie: If you start a console exe which connects to your Oculus HMD, any other active Oculus app will freeze and your HMD will be held at the "Please Wait..." screen until your exe is halted.

That might change in the future, with the blocking of external console apps hopefully being a temporary bug in the system rather than an obstruction put in place by Oculus by design but, for now at least, general C++ hacking with the Oculus Rift seems to have come to an end.

That's perfectly fine if you just want to play games and watch movies on your HMD but, if you're a developer who likes to play with their computer equipment and dream up options for parallel programs running alongside your apps, casual development on Oculus has now been stopped in its tracks.

Oculus No Longer a Developer-Friendly Tool

Unlike the DK2 we enjoyed hacking around with under the beta SDKs, the Oculus CV1 no long provides a nifty bundle of sensors we can interact with. Oculus now seems set to become a locked-down 'social experience' which exists to sell you stuff and track how you interact with your friends.

The terms of service for the Oculus are notoriously creepy with no promises that user data and activity history will be kept from targeted advertising in the future.

It's a little sleazy.

Not a comforting image, is it?
Not a comforting image, is it? Photo: Facebook

And more than a little disappointing.

The Oculus DK2 was fun and satisfying to develop with, but the production Oculus toolkit just isn't for me.

If you're wanting to build an app for Oculus, I would recommend sticking with a game development environment like Unity3D or Unreal Engine, as hacking around in C++ with the sensors and other nifty hardware bits seems likely to bring you frustration and pain with the current Oculus development tools.

For fun hacking around of that sort, it seems like it's time to turn to the HTC Vive and Open VR.

To Main Page
Back To Top
To Blog Archive