core_oculus_rift.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Oculus Rift CV1
  4. *
  5. * Compile example using:
  6. * gcc -o $(NAME_PART).exe $(FILE_NAME) -L. -L..\src\external\OculusSDK\LibOVR -lLibOVRRT32_1 -lraylib -lglfw3 -lopengl32 -lgdi32 -std=c99
  7. *
  8. * This example has been created using raylib 1.5 (www.raylib.com)
  9. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  10. *
  11. * Copyright (c) 2016 Ramon Santamaria (@raysan5)
  12. *
  13. ********************************************************************************************/
  14. #include "raylib.h"
  15. int main()
  16. {
  17. // Initialization
  18. //--------------------------------------------------------------------------------------
  19. int screenWidth = 1080;
  20. int screenHeight = 600;
  21. InitWindow(screenWidth, screenHeight, "raylib [core] example - oculus rift");
  22. InitOculusDevice();
  23. // Define the camera to look into our 3d world
  24. Camera camera;
  25. camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position
  26. camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
  27. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
  28. camera.fovy = 45.0f; // Camera field-of-view Y
  29. Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
  30. //SetTargetFPS(90); // Set our game to run at 90 frames-per-second
  31. //--------------------------------------------------------------------------------------
  32. // Main game loop
  33. while (!WindowShouldClose()) // Detect window close button or ESC key
  34. {
  35. // Update
  36. //----------------------------------------------------------------------------------
  37. UpdateOculusTracking();
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. BeginOculusDrawing();
  44. for (int eye = 0; eye < 2; eye++)
  45. {
  46. Begin3dMode(camera);
  47. SetOculusMatrix(eye);
  48. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  49. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  50. DrawGrid(10, 1.0f);
  51. End3dMode();
  52. }
  53. EndOculusDrawing();
  54. EndDrawing();
  55. //----------------------------------------------------------------------------------
  56. }
  57. // De-Initialization
  58. //--------------------------------------------------------------------------------------
  59. CloseOculusDevice(); // Close Oculus Rift device
  60. CloseWindow(); // Close window and OpenGL context
  61. //--------------------------------------------------------------------------------------
  62. return 0;
  63. }