aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-06-03 18:26:59 +0200
committerraysan5 <raysan5@gmail.com>2016-06-03 18:26:59 +0200
commit13bef7aa0215c135074947a28dce92695d456565 (patch)
treec81c40a72105b035ffef79cff356369141db194d /src
parentb574e105dd8790bdc60ffb4876f840ff3316abe4 (diff)
downloadraylib-13bef7aa0215c135074947a28dce92695d456565.tar.gz
raylib-13bef7aa0215c135074947a28dce92695d456565.zip
Work on Oculus functionality
Trying to find the best way to integrate Oculus support into raylib, making it easy for the user...
Diffstat (limited to 'src')
-rw-r--r--src/core.c62
-rw-r--r--src/raylib.h6
2 files changed, 63 insertions, 5 deletions
diff --git a/src/core.c b/src/core.c
index d4db5017..7316c79c 100644
--- a/src/core.c
+++ b/src/core.c
@@ -483,11 +483,6 @@ void CloseWindow(void)
{
UnloadDefaultFont();
-#if defined(PLATFORM_OCULUS)
- UnloadOculusMirror(session, mirror); // Unload Oculus mirror buffer
- UnloadOculusBuffer(session, buffer); // Unload Oculus texture buffers
-#endif
-
rlglClose(); // De-init rlgl
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
@@ -526,6 +521,63 @@ void CloseWindow(void)
TraceLog(INFO, "Window closed successfully");
}
+#if defined(PLATFORM_OCULUS)
+// Init Oculus Rift device
+// NOTE: Device initialization should be done before window creation?
+void InitOculusDevice(void)
+{
+ ovrResult result = ovr_Initialize(NULL);
+ if (OVR_FAILURE(result)) TraceLog(ERROR, "OVR: Could not initialize Oculus device");
+
+ result = ovr_Create(&session, &luid);
+ if (OVR_FAILURE(result))
+ {
+ TraceLog(WARNING, "OVR: Could not create Oculus session");
+ ovr_Shutdown();
+ }
+
+ hmdDesc = ovr_GetHmdDesc(session);
+
+ TraceLog(INFO, "OVR: Product Name: %s", hmdDesc.ProductName);
+ TraceLog(INFO, "OVR: Manufacturer: %s", hmdDesc.Manufacturer);
+ TraceLog(INFO, "OVR: Product ID: %i", hmdDesc.ProductId);
+ TraceLog(INFO, "OVR: Product Type: %i", hmdDesc.Type);
+ TraceLog(INFO, "OVR: Serian Number: %s", hmdDesc.SerialNumber);
+ TraceLog(INFO, "OVR: Resolution: %ix%i", hmdDesc.Resolution.w, hmdDesc.Resolution.h);
+
+ screenWidth = hmdDesc.Resolution.w/2;
+ screenHeight = hmdDesc.Resolution.h/2;
+
+ // Initialize Oculus Buffers
+ layer = InitOculusLayer(session);
+ buffer = LoadOculusBuffer(session, layer.width, layer.height);
+ mirror = LoadOculusMirror(session, hmdDesc.Resolution.w/2, hmdDesc.Resolution.h/2);
+ layer.eyeLayer.ColorTexture[0] = buffer.textureChain; //SetOculusLayerTexture(eyeLayer, buffer.textureChain);
+}
+
+// Close Oculus Rift device
+void CloseOculusDevice(void)
+{
+ UnloadOculusMirror(session, mirror); // Unload Oculus mirror buffer
+ UnloadOculusBuffer(session, buffer); // Unload Oculus texture buffers
+
+ ovr_Destroy(session); // Must be called after glfwTerminate() --> REALLY???
+ ovr_Shutdown();
+}
+
+// Update Oculus Rift tracking (position and orientation)
+void UpdateOculusTracking(void)
+{
+ frameIndex++;
+
+ ovrPosef eyePoses[2];
+ ovr_GetEyePoses(session, frameIndex, ovrTrue, layer.viewScaleDesc.HmdToEyeOffset, eyePoses, &layer.eyeLayer.SensorSampleTime);
+
+ layer.eyeLayer.RenderPose[0] = eyePoses[0];
+ layer.eyeLayer.RenderPose[1] = eyePoses[1];
+}
+#endif
+
// Detect if KEY_ESCAPE pressed or Close icon pressed
bool WindowShouldClose(void)
{
diff --git a/src/raylib.h b/src/raylib.h
index efd96a67..bdaaeb08 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -578,6 +578,12 @@ void InitWindow(int width, int height, struct android_app *state); // Init Andr
void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics
#endif
+#if defined(PLATFORM_OCULUS)
+void InitOculusDevice(void); // Init Oculus Rift device
+void CloseOculusDevice(void); // Close Oculus Rift device
+void UpdateOculusTracking(void); // Update Oculus Rift tracking (position and orientation)
+#endif
+
void CloseWindow(void); // Close Window and Terminate Context
bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed
bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus)