From 8d41683917acf1bc3551dc422a780db2374c6f9a Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 19 Sep 2020 20:42:19 +0200 Subject: [PATCH] REVIEWED: models_skybox example Now supports dynamic panoramic view, just drag and drop --- examples/models/models_skybox.c | 41 ++++++++++++++---- ...esden_square.hdr => dresden_square_1k.hdr} | Bin .../models/resources/dresden_square_2k.hdr | Bin 0 -> 6019615 bytes 3 files changed, 32 insertions(+), 9 deletions(-) rename examples/models/resources/{dresden_square.hdr => dresden_square_1k.hdr} (100%) create mode 100644 examples/models/resources/dresden_square_2k.hdr 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 0000000000000000000000000000000000000000..60b4a4c80d25f783ff9f22d71a7cc33c4fd0b8ce GIT binary patch literal 6019615 zcmY$k4{~(zbo6s};Bt5L^>ws0_)SCD|=~2?;#O9<)iS0=piOZ9gCN53dm-s(v zcT#KOrXhu{UXYVn@>D#Ezu@ ziLVovB>hkPpSU%#C;xxJ|ALl+r-joBZWL}USX6kvfU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