Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

101 рядки
4.3 KiB

5 роки тому
5 роки тому
5 роки тому
5 роки тому
5 роки тому
5 роки тому
6 роки тому
5 роки тому
6 роки тому
5 роки тому
5 роки тому
6 роки тому
5 роки тому
5 роки тому
  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Skybox loading and drawing
  4. *
  5. * This example has been created using raylib 1.8 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2017 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main(void)
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. const int screenWidth = 800;
  17. const int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
  19. // Define the camera to look into our 3d world
  20. Camera camera = { { 1.0f, 1.0f, 1.0f }, { 4.0f, 1.0f, 4.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
  21. // Load skybox model
  22. Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
  23. Model skybox = LoadModelFromMesh(cube);
  24. // Load skybox shader and set required locations
  25. // NOTE: Some locations are automatically set at shader loading
  26. #if defined(PLATFORM_DESKTOP)
  27. skybox.materials[0].shader = LoadShader("resources/shaders/glsl330/skybox.vs", "resources/shaders/glsl330/skybox.fs");
  28. #else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
  29. skybox.materials[0].shader = LoadShader("resources/shaders/glsl100/skybox.vs", "resources/shaders/glsl100/skybox.fs");
  30. #endif
  31. SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT);
  32. // Load cubemap shader and setup required shader locations
  33. #if defined(PLATFORM_DESKTOP)
  34. Shader shdrCubemap = LoadShader("resources/shaders/glsl330/cubemap.vs", "resources/shaders/glsl330/cubemap.fs");
  35. #else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
  36. Shader shdrCubemap = LoadShader("resources/shaders/glsl100/cubemap.vs", "resources/shaders/glsl100/cubemap.fs");
  37. #endif
  38. SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
  39. // Load HDR panorama (sphere) texture
  40. Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
  41. // Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture
  42. // NOTE: New texture is generated rendering to texture, shader computes the sphre->cube coordinates mapping
  43. skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
  44. UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated
  45. UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore
  46. SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode
  47. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  48. //--------------------------------------------------------------------------------------
  49. // Main game loop
  50. while (!WindowShouldClose()) // Detect window close button or ESC key
  51. {
  52. // Update
  53. //----------------------------------------------------------------------------------
  54. UpdateCamera(&camera); // Update camera
  55. //----------------------------------------------------------------------------------
  56. // Draw
  57. //----------------------------------------------------------------------------------
  58. BeginDrawing();
  59. ClearBackground(RAYWHITE);
  60. BeginMode3D(camera);
  61. DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE);
  62. DrawGrid(10, 1.0f);
  63. EndMode3D();
  64. DrawFPS(10, 10);
  65. EndDrawing();
  66. //----------------------------------------------------------------------------------
  67. }
  68. // De-Initialization
  69. //--------------------------------------------------------------------------------------
  70. UnloadShader(skybox.materials[0].shader);
  71. UnloadTexture(skybox.materials[0].maps[MAP_CUBEMAP].texture);
  72. UnloadModel(skybox); // Unload skybox model
  73. CloseWindow(); // Close window and OpenGL context
  74. //--------------------------------------------------------------------------------------
  75. return 0;
  76. }