Work on Oculus functionality
Trying to find the best way to integrate Oculus support into raylib, making it easy for the user...
This commit is contained in:
parent
b574e105dd
commit
13bef7aa02
2 changed files with 63 additions and 5 deletions
62
src/core.c
62
src/core.c
|
@ -483,11 +483,6 @@ void CloseWindow(void)
|
||||||
{
|
{
|
||||||
UnloadDefaultFont();
|
UnloadDefaultFont();
|
||||||
|
|
||||||
#if defined(PLATFORM_OCULUS)
|
|
||||||
UnloadOculusMirror(session, mirror); // Unload Oculus mirror buffer
|
|
||||||
UnloadOculusBuffer(session, buffer); // Unload Oculus texture buffers
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rlglClose(); // De-init rlgl
|
rlglClose(); // De-init rlgl
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
|
@ -526,6 +521,63 @@ void CloseWindow(void)
|
||||||
TraceLog(INFO, "Window closed successfully");
|
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
|
// Detect if KEY_ESCAPE pressed or Close icon pressed
|
||||||
bool WindowShouldClose(void)
|
bool WindowShouldClose(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
void InitWindow(int width, int height, const char *title); // Initialize Window and OpenGL Graphics
|
||||||
#endif
|
#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
|
void CloseWindow(void); // Close Window and Terminate Context
|
||||||
bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed
|
bool WindowShouldClose(void); // Detect if KEY_ESCAPE pressed or Close icon pressed
|
||||||
bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus)
|
bool IsWindowMinimized(void); // Detect if window has been minimized (or lost focus)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue