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:
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!
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!
