From b3f75b91ff6859f5c19c4b1e6b17c78b5e66530f Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 6 Apr 2021 23:23:03 +0200 Subject: [PATCH] REDESIGNED: Vr stereo mode --- examples/core/core_vr_simulator.c | 19 +++++++++++-------- src/core.c | 19 +------------------ src/raylib.h | 2 +- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/examples/core/core_vr_simulator.c b/examples/core/core_vr_simulator.c index ff303ae2d..091b2fc90 100644 --- a/examples/core/core_vr_simulator.c +++ b/examples/core/core_vr_simulator.c @@ -101,19 +101,22 @@ int main(void) ClearBackground(RAYWHITE); - BeginVrStereoMode(target, config); - BeginMode3D(camera); + BeginTextureMode(target); + ClearBackground(RAYWHITE); + BeginVrStereoMode(config); + BeginMode3D(camera); - DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); - DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); + DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); + DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); - DrawGrid(40, 1.0f); + DrawGrid(40, 1.0f); - EndMode3D(); - EndVrStereoMode(); + EndMode3D(); + EndVrStereoMode(); + EndTextureMode(); BeginShaderMode(distortion); - DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height }, (Vector2){ 0.0f, 0.0f }, WHITE); + DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height }, (Vector2){ 0.0f, 0.0f }, WHITE); EndShaderMode(); DrawFPS(10, 10); diff --git a/src/core.c b/src/core.c index fd77bb85a..2cce9f429 100644 --- a/src/core.c +++ b/src/core.c @@ -2067,36 +2067,19 @@ void EndScissorMode(void) } // Begin VR drawing configuration -void BeginVrStereoMode(RenderTexture2D target, VrStereoConfig config) +void BeginVrStereoMode(VrStereoConfig config) { -#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) - rlEnableFramebuffer(target.id); // Setup framebuffer for stereo rendering - //glEnable(GL_FRAMEBUFFER_SRGB); // Enable SRGB framebuffer (only if required) - rlClearScreenBuffers(); // Clear current framebuffer - rlEnableStereoRender(); // Set stereo render matrices rlSetMatrixProjectionStereo(config.projection[0], config.projection[1]); rlSetMatrixViewOffsetStereo(config.viewOffset[0], config.viewOffset[1]); -#endif } // End VR drawing process (and desktop mirror) void EndVrStereoMode(void) { -#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) rlDisableStereoRender(); - - rlDisableFramebuffer(); // Unbind current framebuffer - - // Reset viewport and default projection-modelview matrices - rlViewport(0, 0, GetScreenWidth(), GetScreenHeight()); - rlSetMatrixProjection(MatrixOrtho(0.0, GetScreenWidth(), GetScreenHeight(), 0.0, 0.0, 1.0)); - rlSetMatrixModelview(MatrixIdentity()); - - rlDisableDepthTest(); -#endif } // Load VR stereo config for VR simulator device parameters diff --git a/src/raylib.h b/src/raylib.h index e8d45a910..4c70e48af 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -965,7 +965,7 @@ RLAPI void BeginBlendMode(int mode); // Begin blend RLAPI void EndBlendMode(void); // End blending mode (reset to default: alpha blending) RLAPI void BeginScissorMode(int x, int y, int width, int height); // Begin scissor mode (define screen area for following drawing) RLAPI void EndScissorMode(void); // End scissor mode -RLAPI void BeginVrStereoMode(RenderTexture2D target, VrStereoConfig config); // Begin stereo rendering (requires VR simulator) +RLAPI void BeginVrStereoMode(VrStereoConfig config); // Begin stereo rendering (requires VR simulator) RLAPI void EndVrStereoMode(void); // End stereo rendering (requires VR simulator) // VR stereo config functions for VR simulator