summaryrefslogtreecommitdiffhomepage
path: root/examples/models/models_skybox.c
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-09-19 20:42:19 +0200
committerraysan5 <[email protected]>2020-09-19 20:42:19 +0200
commit8d41683917acf1bc3551dc422a780db2374c6f9a (patch)
tree3f7ee89750787e9d398fbff4933e1d28b76ddefa /examples/models/models_skybox.c
parent789c5fbdf92df93ade774c2d3132e5ae2a207713 (diff)
downloadraylib-8d41683917acf1bc3551dc422a780db2374c6f9a.tar.gz
raylib-8d41683917acf1bc3551dc422a780db2374c6f9a.zip
REVIEWED: models_skybox example
Now supports dynamic panoramic view, just drag and drop
Diffstat (limited to 'examples/models/models_skybox.c')
-rw-r--r--examples/models/models_skybox.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c
index 8d271cc0..054ea771 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();