Skip to content

Migrating from OVR C API to Python

Christopher Bruns edited this page Oct 24, 2015 · 12 revisions

Identifier prefixes become module namespace specifiers

Many function names, constants, and type names in the C OVR API begin with prefixes such as "ovr", "OVR_", or "ovr_". These prefixes are removed in the Python API because all of these identifiers are in the python "ovr" module namespace.

For example, the C code

OVR_KEY_IPD

would become in python

ovr.KEY_IPD

In the Python API, identifiers are changed like so:

  1. All OVR API identifiers are in the "ovr" module namespace
  2. Prefix "ovr", "OVR_", or "ovr_" is stripped off: OVR_KEY_IPD becomes ovr.KEY_IPD
  3. Function names begin with a lower case letter: ovr_Shutdown() becomes ovr.shutdown()
  4. Type names, macros, and enum values retain their capitalization: ovrTrackingState becomes ovr.TrackingState, OVR_KEY_IPD becomes ovr.KEY_IPD, and ovrTrackingCap_Orientation becomes ovr.TrackingCap_Orientation

Status return values become Exceptions

Many OVR functions in the C API return a value of type ovrResult. The corresponding functions in the Python API do not return an ovrResult, but rather raise an exception, in the case where ovrResult was not OVR_SUCCESS.

For example, the C code

ovrResult result = ovr_Initialize(nullptr);
if (OVR_FAILURE(result))
    return;

becomes

try:
    ovr.initialize(None)
except:
    return

Output arguments become return values

ovrSession session;
ovrGraphicsLuid luid;
result = ovr_Create(&session, &luid);

becomes

session, luid = ovr.create()
Clone this wiki locally