You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.7 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Basic 3d example
  4. *
  5. * Welcome to raylib!
  6. *
  7. * To compile example, just press F5.
  8. * Note that compiled executable is placed in the same folder as .c file
  9. *
  10. * You can find all basic examples on C:\raylib\raylib\examples folder or
  11. * raylib official webpage: www.raylib.com
  12. *
  13. * Enjoy using raylib. :)
  14. *
  15. * This example has been created using raylib 1.0 (www.raylib.com)
  16. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  17. *
  18. * Copyright (c) 2013-2022 Ramon Santamaria (@raysan5)
  19. *
  20. ********************************************************************************************/
  21. #include "raylib.h"
  22. #if defined(PLATFORM_WEB)
  23. #include <emscripten/emscripten.h>
  24. #endif
  25. //----------------------------------------------------------------------------------
  26. // Local Variables Definition (local to this module)
  27. //----------------------------------------------------------------------------------
  28. Camera camera = { 0 };
  29. Vector3 cubePosition = { 0 };
  30. //----------------------------------------------------------------------------------
  31. // Local Functions Declaration
  32. //----------------------------------------------------------------------------------
  33. static void UpdateDrawFrame(void); // Update and draw one frame
  34. //----------------------------------------------------------------------------------
  35. // Main entry point
  36. //----------------------------------------------------------------------------------
  37. int main()
  38. {
  39. // Initialization
  40. //--------------------------------------------------------------------------------------
  41. const int screenWidth = 800;
  42. const int screenHeight = 450;
  43. InitWindow(screenWidth, screenHeight, "raylib");
  44. camera.position = (Vector3){ 10.0f, 10.0f, 8.0f };
  45. camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
  46. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
  47. camera.fovy = 60.0f;
  48. camera.projection = CAMERA_PERSPECTIVE;
  49. SetCameraMode(camera, CAMERA_ORBITAL);
  50. //--------------------------------------------------------------------------------------
  51. #if defined(PLATFORM_WEB)
  52. emscripten_set_main_loop(UpdateDrawFrame, 60, 1);
  53. #else
  54. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  55. //--------------------------------------------------------------------------------------
  56. // Main game loop
  57. while (!WindowShouldClose()) // Detect window close button or ESC key
  58. {
  59. UpdateDrawFrame();
  60. }
  61. #endif
  62. // De-Initialization
  63. //--------------------------------------------------------------------------------------
  64. CloseWindow(); // Close window and OpenGL context
  65. //--------------------------------------------------------------------------------------
  66. return 0;
  67. }
  68. // Update and draw game frame
  69. static void UpdateDrawFrame(void)
  70. {
  71. // Update
  72. //----------------------------------------------------------------------------------
  73. UpdateCamera(&camera);
  74. //----------------------------------------------------------------------------------
  75. // Draw
  76. //----------------------------------------------------------------------------------
  77. BeginDrawing();
  78. ClearBackground(RAYWHITE);
  79. BeginMode3D(camera);
  80. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  81. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  82. DrawGrid(10, 1.0f);
  83. EndMode3D();
  84. DrawText("This is a raylib example", 10, 40, 20, DARKGRAY);
  85. DrawFPS(10, 10);
  86. EndDrawing();
  87. //----------------------------------------------------------------------------------
  88. }