core_3d_mode.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Initialize 3d mode
  4. *
  5. * This example has been created using raylib 1.0 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode");
  19. // Define the camera to look into our 3d world
  20. Camera camera;
  21. camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
  22. camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
  23. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
  24. camera.fovy = 45.0f; // Camera field-of-view Y
  25. Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
  26. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  27. //--------------------------------------------------------------------------------------
  28. // Main game loop
  29. while (!WindowShouldClose()) // Detect window close button or ESC key
  30. {
  31. // Update
  32. //----------------------------------------------------------------------------------
  33. // TODO: Update your variables here
  34. //----------------------------------------------------------------------------------
  35. // Draw
  36. //----------------------------------------------------------------------------------
  37. BeginDrawing();
  38. ClearBackground(RAYWHITE);
  39. Begin3dMode(camera);
  40. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  41. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  42. DrawGrid(10, 1.0f);
  43. End3dMode();
  44. DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY);
  45. DrawFPS(10, 10);
  46. EndDrawing();
  47. //----------------------------------------------------------------------------------
  48. }
  49. // De-Initialization
  50. //--------------------------------------------------------------------------------------
  51. CloseWindow(); // Close window and OpenGL context
  52. //--------------------------------------------------------------------------------------
  53. return 0;
  54. }