diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 32e6b1c6..e0ab61fd 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -52,14 +52,9 @@ int main() ClearBackground(RAYWHITE); Begin3dMode(camera); - //BeginOculusDrawing(camera); // Add it to Begin3dMode() ? - + for (int eye = 0; eye < 2; eye++) { - // TODO: Probably projection and view matrices could be created here... - // ...without the need to create it internally through Begin3dMode() - //Begin3dMode(camera); - SetOculusView(eye); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); @@ -67,15 +62,10 @@ int main() DrawGrid(10, 1.0f); - // TODO: Call internal buffers drawing directly (rlglDraw()) and... - // ...reset internal matrices, instead of letting End3dMode() do that - //End3dMode(); - DrawDefaultBuffers(); // Process internal dynamic buffers } End3dMode(); - //EndOculusDrawing(); // Add it to End3dMode() ? EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/src/core.c b/src/core.c index eef81bad..af82e092 100644 --- a/src/core.c +++ b/src/core.c @@ -607,13 +607,14 @@ void Begin3dMode(Camera camera) rlEnableDepthTest(); // Enable DEPTH_TEST for 3D - //if (vrEnabled) BeginVrMode(); + if (VrEnabled()) BeginOculusDrawing(); } // Ends 3D mode and returns to default 2D orthographic mode void End3dMode(void) { - rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2) + if (VrEnabled()) EndOculusDrawing(); + else rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2) rlMatrixMode(RL_PROJECTION); // Switch to projection matrix rlPopMatrix(); // Restore previous matrix (PROJECTION) from matrix stack diff --git a/src/rlgl.c b/src/rlgl.c index 2d4d951c..eee19ef4 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -76,7 +76,7 @@ #include "standard_shader.h" // Standard shader to embed #endif -#define RLGL_OCULUS_SUPPORT // Enable Oculus Rift code +//#define RLGL_OCULUS_SUPPORT // Enable Oculus Rift code #if defined(RLGL_OCULUS_SUPPORT) #include "external/OculusSDK/LibOVR/Include/OVR_CAPI_GL.h" // Oculus SDK for OpenGL #endif @@ -268,6 +268,7 @@ static unsigned int frameIndex = 0; // Oculus frames counter, used to discar #endif static bool vrSimulator = false; // VR simulator (stereo rendering on window, without vr device) +static bool vrEnabled = false; // VR enabled flag (required by core module) // Compressed textures support flags static bool texCompDXTSupported = false; // DDS texture compression support @@ -2523,6 +2524,7 @@ void InitOculusDevice(void) } #else vrSimulator = true; + vrEnabled = true; #endif if (vrSimulator) @@ -2548,6 +2550,14 @@ void CloseOculusDevice(void) // TODO: Unload stereo framebuffer and texture // TODO: Unload oculus-distortion shader } + + vrEnabled = false; +} + +// Track stereoscopic rendering +bool VrEnabled(void) +{ + return vrEnabled; } // Update Oculus Rift tracking (position and orientation) diff --git a/src/rlgl.h b/src/rlgl.h index e2e1dde6..c0e93a65 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -362,6 +362,7 @@ void UpdateOculusTracking(void); // Update Oculus Rift tracking (posi void SetOculusView(int eye); // Set internal projection and modelview matrix depending on eyes tracking data void BeginOculusDrawing(void); // Begin Oculus drawing configuration void EndOculusDrawing(void); // End Oculus drawing process (and desktop mirror) +bool VrEnabled(void); // Track stereoscopic rendering #ifdef __cplusplus }