这个例子是初始化LibOVR和请求关于有效HMD的信息。
回顾下面的代码:
// Include the OculusVR SDK
#include <OVR_CAPI.h>
void Application()
{
ovrResult result = ovr_Initialize(nullptr);
if (OVR_FAILURE(result))
return;
ovrSession session;
ovrGraphicsLuid luid;
result = ovr_Create(&session, &luid);
if (OVR_FAILURE(result))
{
ovr_Shutdown();
return;
}
ovrHmdDesc desc = ovr_GetHmdDesc(session);
ovrSizei resolution = desc.Resolution;
ovr_Destroy(session);
ovr_Shutdown();
}
就像你看到的,ovr_Initialize在任何API函数之前调用和ovr_Shutdown在你退出游戏之前来关闭这个库。在这两个函数之间,你可以自由的创建HMD对象,使用追踪状态,和执行应用渲染。
在这个例子中,ovr_Create(&session&luid)创建HMD。使用ovr_Create()返回的LUID去选择IDXGIAdapter在你创建的ID3D11Device或者ID3D12Device上.最后,ovr_Destroy必须被调用去清理HMD在关闭库之前。
你能使用ovr_GetHmdDesc()去获得一个HMD的描述。
如果没有Rift没有插上,ovr_Create(&session,&luid)会返回一个失败的ovrResult除非一个虚拟的HMD是可以的通过RiftConfigUtil.虽然虚拟HMD不会提供任何传感器输入,它能调试Rift-compatible渲染代码和开发不用物理设备。
一个HMD的描述句柄能被恢复通过调用ovr_GetHmdDesc(session)。下面的表描述这些域:
Field Type Description
Type ovrHmdType Type of the HMD, such as ovr_DK2 or ovr_DK2 .
ProductName char[] Name of the product as a string.
Manufacturer char[] Name of the manufacturer.
VendorId short Vendor ID reported by the headset USB device.
ProductId short Product ID reported by the headset USB device.
SerialNumber char[] Serial number string reported by the headset USB deviceFirmwareMajor short The major version of the sensor firmware.
FirmwareMinor short The minor version of the sensor firmware.