LibOVR Integration
The Oculus SDK is designed to be as easy to integrate as possible. This guide outlines a basic integration with a C/C++ game engine or application.
We’ll discuss initializing the LibOVR, HMD device enumeration, head tracking, frame timing, and rendering for the Rift.
Many of the code samples below are taken directly from the OculusRoomTiny demo source code (available in Oculus/Samples/OculusRoomTiny
). OculusRoomTiny and OculusWorldDemo are great places to view sample integration code when in doubt about a particular system or feature.
There are three major phases when using the SDK: setup, the game loop, and shutdown.
To add Oculus SDK support to a new application, do the following:
- Initialize LibOVR through
ovr_Initialize
. - Call
ovr_Create
and check the return value to see if it succeeded. You can periodically poll for the presence of an HMD with ovr_GetHmdDesc(nullptr)
. - Integrate head-tracking into your application’s view and movement code. This involves:
- Obtaining predicted headset orientation for the frame through a combination of the
GetPredictedDisplayTime
and ovr_GetTrackingState
calls. - Applying Rift orientation and position to the camera view, while combining it with other application controls.
- Modifying movement and game play to consider head orientation.
- Initialize rendering for the HMD.
- Select rendering parameters such as resolution and field of view based on HMD capabilities. See:
ovr_GetFovTextureSize
and ovr_GetRenderDesc
. - Configure rendering by creating D3D/OpenGL-specific swap texture sets to present data to the headset. See:
ovr_CreateTextureSwapChainDX
and ovr_CreateTextureSwapChainGL
.
- Modify application frame rendering to integrate HMD support and proper frame timing:
- Make sure your engine supports rendering stereo views.
- Add frame timing logic into the render loop to obtain correctly predicted eye render poses.
- Render each eye’s view to intermediate render targets.
- Submit the rendered frame to the headset by calling the functions
ovr_WaitToBeginFrame
, ovr_BeginFrame
, and ovr_EndFrame
.
- Customize UI screens to work well inside of the headset.
- Destroy the created resources during shutdown. See:
ovr_DestroyTextureSwapChain
, ovr_Destroy
, and ovr_Shutdown
.