This website uses cookies to improve our services and deliver relevant ads.
By interacting with this site, you agree to this use. For more information, see our Cookies Policy

Platform 1.32 Reference Guide

How do I Oculus Platform?

The only header you need to include directly is OVR_Platform.h, as it includes all other Platform SDK headers.
See here for a list of all headers.

  1. Initialize :
    See OVR_Platform.h for initialization functions.
  2. Request:
    Make some requests! See below for a full list of requests.
  3. Handle Responses:
    Retrieve responses from the message queue and process them.

#include "OVR_Platform.h"

#include <stdio.h>

int main() {
  // initialize the platform SDK
  ovrPlatformInitializeResult initializeResult = ovr_PlatformInitializeWindows("PUT_YOUR_APP_ID_HERE");

  // quit if initialization failed
  if (initializeResult < 0) {
    puts("Initialization failed");
    return 1;
  }

  // get the logged in user's id
  // this is not a request, so it returns the data directly
  ovrID loggedInUserID = ovr_GetLoggedInUserID();
  if (loggedInUserID == 0) {
    puts("No logged in user");
    return 1;
  }

  // initiate a request to get the logged in users's information
  // this is a request, so the response is returned on the message queue
  ovr_User_Get(loggedInUserID);

  // main loop
  for (;;) {

    // pop messages off of the message queue until it is empty
    for(;;) {
      ovrMessageHandle message = ovr_PopMessage();
      if (message == NULL) {
        break;
      }

      // first check for errors
      if (ovr_Message_IsError(message)) {
        ovrErrorHandle error = ovr_Message_GetError(message);
        puts("Got an error");
        puts(ovr_Error_GetMessage(error));
        return 1;
      }

      // get the message type
      ovrMessageType messageType = ovr_Message_GetType(message);

      // handle the response
      if (messageType == ovrMessage_User_Get) {
        ovrUserHandle user = ovr_Message_GetUser(message);
        puts("Got a user");
        printf("Username: %s", ovr_User_GetOculusID(user));
      } else {
        // Normally, you would handle other message types, but we'll just ignore them
        // for this example
      }

      ovr_FreeMessage(message);
    }
  }
}