Skip to main content
Up and Coming
October 3, 2014

Barebones, one file D3D11 Direct-to-Rift example

I was having a lot of trouble getting Direct-to-Rift mode working with my project, and it seems I'm not alone in that. It seems there's plenty of confusion on the forums about how to get it to work (assuming your drivers support it at all), and Oculus has been bafflingly quiet on the subject. I found that the Oculus sample apps (Tiny Rooms and Oculus World) worked very consistently for me (GTX 970), so I decided to tear them down until I could identify the minimum amount of code needed to successfully invoke Direct-to-Rift mode with D3D11. I've put the result up on Github:

https://github.com/toji/BarebonesDirectToRift/blob/master/Win32_BarebonesDirect.cpp

Somewhat to my surprise it doesn't seem to have much to do with how you created your SwapChain or anything like that. The key points are:


  • Call ovr_InitializeRenderingShim or ovr_Initialize before creating the graphics device. Doesn't matter when it's called in relation to the window creation.

  • Call ovrHmd_AttachToWindow sometime after creating the window and HMD. Doesn't matter when it's called in relation to graphics device creation.

  • Call ovrHmd_GetTrackingState or ovrHmd_GetEyePose at least once, possibly required to be on the same thread that you created the window or graphics device on.


That last one surprised me, as it's apparently the magic sauce that actually makes Direct-to-Rift mode work.
Interestingly it doesn't need to be called in the render loop, you can call it once after ovrHmd_AttachToWindow and never again, it still initializes the display correctly. This is really weird, because basically EVERY Rift application will call this during it's game loop, so you would think that most apps should "just work". That's why I theorize that it may need to be called on the main window/graphics device thread.

Anyway, hope that helps some devs out there get this working! Happy coding!

    4 replies

    Inspiring
    October 3, 2014
    Thanks for posting this. I'm sure it will help some people.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Participant
    November 2, 2014
    First of all, thanks for this. I'm not really developing anything at the moment, but I am interested in why Direct-To-Rift is still so fragile (although it has certainly been improved!).

    "Tojiro" wrote:

  • Call ovr_InitializeRenderingShim or ovr_Initialize before creating the graphics device. Doesn't matter when it's called in relation to the window creation.


  • I think this is because Direct-to-Rift works by hooking into certain graphics API (Direct3D/OpenGL) functions. If you don't call ovr_Initialize() before creating swap chains etc., the OVR runtime hasn't had a chance to initialize those hooks. Therefore it's not able to override certain values and D2R will likely not (fully) work.
    New Participant
    June 19, 2015
    Very helpful. When I build this, error c1083 is returned, "cannot open include file: 'OVR_CAPI.h': No such file or directory". Have the sdk (two of the three include files were recognized) and the OVR_CAPI.h file is in place in the "Include" directory of the sdk. Any thoughts as to why this may happen?
    Inspiring
    June 19, 2015
    If you are using Visual Studio, you should check to make sure the Oculus include directory is listed inside the project settings under: "C++ -> General -> Additional Include Directories".
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV