REVIEWED: models_skybox example
Now supports dynamic panoramic view, just drag and drop
This commit is contained in:
parent
789c5fbdf9
commit
8d41683917
3 changed files with 32 additions and 9 deletions
|
@ -2,10 +2,10 @@
|
||||||
*
|
*
|
||||||
* raylib [models] example - Skybox loading and drawing
|
* 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)
|
* 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);
|
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
|
||||||
|
|
||||||
// Load HDR panorama (sphere) texture
|
// 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
|
// 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
|
// 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
|
UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
|
||||||
UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore
|
|
||||||
|
|
||||||
SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode
|
SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode
|
||||||
|
|
||||||
|
@ -66,6 +67,30 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera); // Update camera
|
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
|
// Draw
|
||||||
|
@ -75,13 +100,11 @@ int main(void)
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
|
|
||||||
DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE);
|
DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE);
|
||||||
|
|
||||||
DrawGrid(10, 1.0f);
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
|
DrawText(TextFormat("Panorama image from hdrihaven.com: %s", GetFileName(panoFileName)), 10, GetScreenHeight() - 20, 10, BLACK);
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
BIN
examples/models/resources/dresden_square_2k.hdr
Normal file
BIN
examples/models/resources/dresden_square_2k.hdr
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue