Skip to content

Commit

Permalink
revised readme and starting on basic OpenXR stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ixchow committed Nov 3, 2023
1 parent f090094 commit 1459b08
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 11 deletions.
5 changes: 4 additions & 1 deletion Maekfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const maek = init_maek();
//======================================================================

const NEST_LIBS = `../nest-libs/${maek.OS}`;
const OPENXR_SDK = `../openxr-sdk-source`;

//set compile flags (these can also be overridden per-task using the "options" parameter):
if (maek.OS === "windows") {
Expand Down Expand Up @@ -49,7 +50,9 @@ if (maek.OS === "windows") {
//include paths for nest libraries:
`-I${NEST_LIBS}/SDL2/include/SDL2`, `-D_THREAD_SAFE`, //the output of sdl-config --cflags
`-I${NEST_LIBS}/glm/include`,
`-I${NEST_LIBS}/libpng/include`
`-I${NEST_LIBS}/libpng/include`,
//OpenXR:
`-I${OPENXR_SDK}/include`
);
maek.options.LINKLibs.push(
//linker flags for nest libraries:
Expand Down
81 changes: 73 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,80 @@
# (TODO: your game's title)
# 15-466 Demonstration Code - NDK + OpenXR

Author: (TODO: your name)
This demonstration code shows how to use a `Maekfile.js` to build with the NDK for Android devices, and how to use OpenXR on such devices.

Design: (TODO: In two sentences or fewer, describe what is new and interesting about your game.)
Particularly, this code is designed to build for Meta Quest 3.

Screen Shot:
Based on [15-466-f23-base2](https://github.com/15-466/15-466-f23-base2) with modifications inspired by both the [Oculus OpenXR Mobile SDK](https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/) samples and the [OpenXR Source SDK](https://github.com/KhronosGroup/OpenXR-SDK-Source) samples.

![Screen Shot](screenshot.png)
## Setup

How To Play:
You will need to jump through some hoops to get your development environment set up, and to get your hardware ready for development.

(TODO: describe the controls and (if needed) goals/strategy.)
### Software

This game was built with [NEST](NEST.md).
Get the android sdk set up in a directory which is a sibling of this one using the `sdkmanager` utility. (Note, these instructions are based on https://developer.android.com/tools/sdkmanager .)


Start with a "command line tools only" package from https://developer.android.com/studio (scroll to the bottom). Now extract it and get it working:

```
$ mkdir android-sdk
$ cd android-sdk
$ unzip ../downloads/commandlinetools-linux-10406996_latest.zip
$ cd cmdline-tools
$ mkdir latest
#will complain about moving latest into itself, which is fine:
$ mv * latest
```

Now get the things that the ovr SDK says we need (as per https://developer.oculus.com/documentation/native/android/mobile-studio-setup-android/ ):
```
#from android-sdk:
$ ./cmdline-tools/latest/bin/sdkmanager --install 'platforms;android-26'
# "version 28.0.3 or later"; latest as of --list is build-tools;34.0.0-rc3 but:
$ ./cmdline-tools/latest/bin/sdkmanager --install 'build-tools;28.0.3'
# android NDK (no version given, this is latest as of this writing):
$ ./cmdline-tools/latest/bin/sdkmanager --install 'ndk;26.1.10909125'
```

Also download Meta's OpenXR SDK (from https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/) and extract into a sibling of this directory:
```
$ mkdir ovr-openxr-sdk
$ cd ovr-openxr-sdk
$ unzip ../downloads/ovr_openxr_mobile_sdk_57.0.zip #current version as of this writing
```

Once all of that is done you should have these three as siblings:
```
15466-f23-ndk-openxr #this folder
android-sdk #android sdk, tools, etc
ovr-openxr-sdk #Meta's OpenXR SDK stuff
```

### Hardware

Set up your Quest 3 for development, as per https://developer.oculus.com/documentation/native/android/mobile-device-setup/ .
- create a developer acct: https://developer.oculus.com/manage/organizations/create/
- might require setting up 2FA at: https://developer.oculus.com/manage/verify/
- from oculus phone app: headset -> settings -> developer mode [set to: on]
- connect via USB C (the included white cable works, though is annoyingly short) and allow data (notification will pop up in headset)


You can now connect to the headset via the `adb` tool:
```
#from android-sdk:
$ ./platform-tools/adb devices
# shows "unauthorized" and causes the "allow debugging" dialog to pop on the headset
# if dialog accepted, says "device" next to the device (maybe that's the device name?)
$ ./platform-tools/adb devices
# if you like to explore a bit, get a shell on your device:
$ ./platform-tools/adb shell
# interesting things include `top` (see what's running), `cat /proc/cpuinfo` (learn more about the cpu)
#(ctrl-d to exit)
```

## Building


...
59 changes: 57 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@
//for screenshots:
#include "load_save_png.hpp"

#ifdef __ANDROID__
//libSDL not used on android(!)
#else
//Includes for libSDL:
#include <SDL.h>
#endif

//for OpenXR:
#include <openxr/openxr.h>
#define XR_USE_GRAPHICS_API_OPENGL
#include <openxr/openxr_platform.h>

//...and for c++ standard library functions:
#include <chrono>
#include <iostream>
#include <stdexcept>
#include <memory>
#include <algorithm>
#include <cstring>

#ifdef _WIN32
extern "C" { uint32_t GetACP(); }
Expand All @@ -42,7 +52,52 @@ int main(int argc, char **argv) {
try {
#endif

//------------ initialization ------------
//------------ OpenXR init ------------

{
//OpenXR needs an "instance" to store global state:
XrInstance instance{XR_NULL_HANDLE};
XrInstanceCreateInfo create_info{XR_TYPE_INSTANCE_CREATE_INFO};

//with reference to openxr_program.cpp from openxr-sdk-source + the openxr specification

std::strcpy(create_info.applicationInfo.applicationName, "gp23 openxr demo");
create_info.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;

//TODO: ON ANROID --> set create_info->next to point to an XrInstanceCreateInfoAndroidKHR structure
// filled in as per openxr-sdk-source's platformplugin_android.cpp

std::vector< const char * > extensions{
XR_KHR_OPENGL_ENABLE_EXTENSION_NAME,
//TOOD: ON ANROID --> XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME
};

create_info.enabledExtensionCount = uint32_t(extensions.size());
create_info.enabledExtensionNames = extensions.data();

if (XrResult res = xrCreateInstance( &create_info, &instance);
res != XR_SUCCESS) {
std::cerr << "Failed to create OpenXR instance: " << res << std::endl;
return 1;
}

//Query the instance to learn what runtime this is using:
XrInstanceProperties properties{XR_TYPE_INSTANCE_PROPERTIES};
if (XrResult res = xrGetInstanceProperties(instance, &properties);
res != XR_SUCCESS) {
std::cerr << "Failed to get OpenXR instance properties: " << res << std::endl;
return 1;
}
std::cout << "OpenXR Runtime is '" << properties.runtimeName << "', version "
<< (properties.runtimeVersion >> 48)
<< "." << ((properties.runtimeVersion >> 32) & 0xffff)
<< "." << (properties.runtimeVersion & 0xffffffff)
<< std::endl;

//TODO, later: xrDestroyInstance !
}

//------------ initialization ------------

//Initialize SDL library:
SDL_Init(SDL_INIT_VIDEO);
Expand All @@ -63,7 +118,7 @@ int main(int argc, char **argv) {

//create window:
SDL_Window *window = SDL_CreateWindow(
"gp23 game2: enter the matr... virtual world", //TODO: remember to set a title for your game!
"gp23: openxr demo code", //TODO: remember to set a title for your game!
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
1280, 720, //TODO: modify window size if you'd like
SDL_WINDOW_OPENGL
Expand Down

0 comments on commit 1459b08

Please sign in to comment.