diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index 8d271cc0c..054ea7718 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -2,10 +2,10 @@ * * raylib [models] example - Skybox loading and drawing * -* This example has been created using raylib 1.8 (www.raylib.com) +* This example has been created using raylib 3.1 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2017 Ramon Santamaria (@raysan5) +* Copyright (c) 2017-2020 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -46,14 +46,15 @@ int main(void) SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT); // Load HDR panorama (sphere) texture - Texture2D texHDR = LoadTexture("resources/dresden_square.hdr"); + char panoFileName[256] = { 0 }; + TextCopy(panoFileName, "resources/dresden_square_2k.hdr"); + Texture2D panorama = LoadTexture(panoFileName); // Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture // NOTE: New texture is generated rendering to texture, shader computes the sphre->cube coordinates mapping - skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512); + skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024); - UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated - UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore + UnloadTexture(panorama); // Texture not required anymore, cubemap already generated SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode @@ -66,6 +67,30 @@ int main(void) // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update camera + + // Load new cubemap texture on drag&drop + if (IsFileDropped()) + { + int count = 0; + char **droppedFiles = GetDroppedFiles(&count); + + if (count == 1) // Only support one file dropped + { + if (IsFileExtension(droppedFiles[0], ".png;.jpg;.hdr;.bmp;.tga")) + { + // Unload current cubemap texture and load new one + UnloadTexture(skybox.materials[0].maps[MAP_CUBEMAP].texture); + panorama = LoadTexture(droppedFiles[0]); + TextCopy(panoFileName, droppedFiles[0]); + + // Generate cubemap from panorama texture + skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 512); + UnloadTexture(panorama); + } + } + + ClearDroppedFiles(); // Clear internal buffers + } //---------------------------------------------------------------------------------- // Draw @@ -75,13 +100,11 @@ int main(void) ClearBackground(RAYWHITE); BeginMode3D(camera); - DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE); - DrawGrid(10, 1.0f); - EndMode3D(); + DrawText(TextFormat("Panorama image from hdrihaven.com: %s", GetFileName(panoFileName)), 10, GetScreenHeight() - 20, 10, BLACK); DrawFPS(10, 10); EndDrawing(); diff --git a/examples/models/resources/dresden_square.hdr b/examples/models/resources/dresden_square_1k.hdr similarity index 100% rename from examples/models/resources/dresden_square.hdr rename to examples/models/resources/dresden_square_1k.hdr diff --git a/examples/models/resources/dresden_square_2k.hdr b/examples/models/resources/dresden_square_2k.hdr new file mode 100644 index 000000000..60b4a4c80 Binary files /dev/null and b/examples/models/resources/dresden_square_2k.hdr differ