4 | Update Your App | Oculus Platform
Update Your App
This section describes how to prepare your app or experience for the Oculus Platform features.
Adding Oculus Platform Support to Your Project
To add Oculus Platform support to your Visual C++ project:
1. Open the Properties page.
2. Select VC++ Directories.
3. Add the location of the SDK includes folder (InstallFolder\include) to Include Directories.
4. Add the location of the lib file (InstallFolder\Windows) to Library Directories.
5. Expand Linker and select Input.
6. Add the loader library (LibOVRPlatform32_1.lib or LibOVRPlatform64_1.lib) to Additional Dependencies.
7. Using the DLL loader instead of direct linking enables DLL signature verification and graceful detection of the Oculus Runtime. To use the loader, drop the cpp file (InstallFolder/Windows/OVR_PlatformLoader.cpp ) into your project.
To bypass the Loader, add this define before including OVR_Platform.
#define OVRPL_DISABLED
#include <OVR_Platform.h>
Making REST Requests
Depending on the type of operation, you might use the Platform UI or API.
Although many requests are made in the UI, eventually you will be able to make most of them programmatically. This section describes how to make REST requests.
Before you can make a request, make sure you have the credentials for your app. For more information, see
Oculus Platform Setup .
Many types of requests to the API use the following format:
[GET/POST/DELETE] https://graph.oculus.com/app_id/api
?access_token=token|app_id|app_secret
&option_1=<option-1>
&option_2=<option-2>
... where:
• app_id—ID of the app.
• api—name of the API (e.g., "leaderboards").
• token—Request token.
• app_secret—the secret key for the app.
Oculus Platform | Update Your App | 5
• option_1, option_2, ...—options specific to the API.
The following is an example request that creates a leaderboard:
[POST]https://graph.oculus.com/3294569807254367/leaderboards?access_token=OC|3294569807254367|
971bf33c22d4e56438900334be288e43&api_name=game-leaders&sort_order=HIGHER_IS_BETTER>
Note: All requests are encrypted; only the endpoint (graph.oculus.com) is passed in the clear.
Native Rift and Gear VR Apps
This section describes how to set up your app for native C++ development.
Initializing in Production
To ensure that your game is ready for the Oculus Store, you need to add code that ensures each user has an entitlement for your app.
Depending on your development environment, there are different ways to verify entitlements. This section describes how to check entitlements for native C++ apps.
Applications that run in a production environment and are launched from the Oculus App use a call, similar to the following, that passes in your AppID:
// Initialization call if (ovr_PlatformInitializeWindows(appID) != ovrPlatformInitialize_Success)
{
// Exit. Initialization failed which means either the oculus service isn’t on the machine or
they’ve hacked their DLL
} ovr_Entitlement_GetIsViewerEntitled();
Use code similar to the following to poll for a response:
// Poll for a response while ((message = ovr_PopMessage()) != nullptr) {
switch (ovr_Message_GetType(message)) {
case ovrMessage_Entitlement_GetIsViewerEntitled: if (!ovr_Message_IsError(message))
{
// User is entitled. Continue with normal game behaviour
} else
{
// User is NOT entitled. Exit
}
break;
default:
break;
}
}
Checking Entitlement in Production
Make the following call, which will return a bool that indicates whether the user is entitled: ovr_Entitlement_GetIsViewerEntitled();
6 | Update Your App | Oculus Platform which will result in a message returned with the results.
Note: If you are using the legacy test token for standalone development, all entitlement checks will pass.
Modifying Your Game Loop
To modify your game loop:
1. Look for messages being sent from the platform by modifying your game loop to call ovr_PopMessage() in a loop until it returns null. These can be returned from a call or a notification sent from the platform.
2. When a message is received, call ovr_Message_GetType() to extract the message type.
3. Use ovr_Message_IsError() to verify if the message contains a failure or a success response.
Messages include different data, based on the type. There are several helper functions in OVR_Platform.h
that parse the data into a convenient struct, which use the ovr_Message_* naming convention.
4. After processing a message, call ovr_FreeMessage() to clean up and prevent memory leaks.
Unity
This section describes how to set up your app for Unity development.
Initializing in Production
To ensure that your game is ready for the Oculus Store, you need to add code that ensures each user has an entitlement for your app.
Depending on your development environment, there are different ways to verify entitlements. This section describes how to check entitlements for Unity apps.
To initialize in Unity, use the Initialize method of the Platform object:
Oculus.Platform.Core.Initialize(appID)
Checking Entitlement in Production
To check for an entitlement:
Platform.Entitlement.IsUserEntitledToApplication().OnComplete(callbackMethod); which will call your callback method when returning the results.
To process the results, use code similar to the following:
void callbackMethod (Message msg)
{
if (!msg.IsError)
{
// Entitlement check passed
}
else
{
// Entitlement check failed
}
}
}
}
Oculus Platform | Update Your App | 7
Note: If you are using the legacy test token for standalone development, all entitlement checks will pass.
Initializing in the Unity Editor
For Unity, you set your test token in the Unity editor. After importing the Oculus Platform wrapper, the Oculus
Platform menu item is added to the editor. Select Platform Settings and paste in your Token.
Then, initialize normally:
Oculus.Platform.Core.Initialize(appID)
Note: Make sure to give an entitlement to the user. For more information, see Entitlements: App
Authorizations on page 8. Make sure you are logged into the Oculus App while developing in a
standalone environment.
Modifying the Game Loop
Add the following call to your Update() method to make sure your callbacks are processed:
Request.RunCallbacks();