Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

108 wiersze
3.6 KiB

11 miesięcy temu
  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-2024 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. //--------------------------------------------------------------------------------------
  50. #if defined(PLATFORM_WEB)
  51. emscripten_set_main_loop(UpdateDrawFrame, 60, 1);
  52. #else
  53. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  54. //--------------------------------------------------------------------------------------
  55. // Main game loop
  56. while (!WindowShouldClose()) // Detect window close button or ESC key
  57. {
  58. UpdateDrawFrame();
  59. }
  60. #endif
  61. // De-Initialization
  62. //--------------------------------------------------------------------------------------
  63. CloseWindow(); // Close window and OpenGL context
  64. //--------------------------------------------------------------------------------------
  65. return 0;
  66. }
  67. // Update and draw game frame
  68. static void UpdateDrawFrame(void)
  69. {
  70. // Update
  71. //----------------------------------------------------------------------------------
  72. UpdateCamera(&camera, CAMERA_ORBITAL);
  73. //----------------------------------------------------------------------------------
  74. // Draw
  75. //----------------------------------------------------------------------------------
  76. BeginDrawing();
  77. ClearBackground(RAYWHITE);
  78. BeginMode3D(camera);
  79. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  80. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  81. DrawGrid(10, 1.0f);
  82. EndMode3D();
  83. DrawText("This is a raylib example", 10, 40, 20, DARKGRAY);
  84. DrawFPS(10, 10);
  85. EndDrawing();
  86. //----------------------------------------------------------------------------------
  87. }