2017-07-17 01:33:40 +03:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
|
|
|
* raylib [models] example - Skybox loading and drawing
|
|
|
|
*
|
|
|
|
* This example has been created using raylib 1.8 (www.raylib.com)
|
|
|
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
|
|
|
*
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
|
2019-05-20 17:36:42 +03:00
|
|
|
int main(void)
|
2017-07-17 01:33:40 +03:00
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
2019-05-20 17:36:42 +03:00
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
2017-07-17 01:33:40 +03:00
|
|
|
|
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
|
|
|
|
|
|
|
|
// Define the camera to look into our 3d world
|
2019-05-27 01:18:15 +03:00
|
|
|
Camera camera = { { 1.0f, 1.0f, 1.0f }, { 4.0f, 1.0f, 4.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
2017-07-17 01:33:40 +03:00
|
|
|
|
2019-05-20 17:36:42 +03:00
|
|
|
// Load skybox model
|
2017-07-17 01:33:40 +03:00
|
|
|
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
2017-07-21 10:34:09 +03:00
|
|
|
Model skybox = LoadModelFromMesh(cube);
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2017-07-21 10:34:09 +03:00
|
|
|
// Load skybox shader and set required locations
|
|
|
|
// NOTE: Some locations are automatically set at shader loading
|
2019-05-18 02:24:00 +03:00
|
|
|
#if defined(PLATFORM_DESKTOP)
|
|
|
|
skybox.materials[0].shader = LoadShader("resources/shaders/glsl330/skybox.vs", "resources/shaders/glsl330/skybox.fs");
|
|
|
|
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
|
|
|
skybox.materials[0].shader = LoadShader("resources/shaders/glsl100/skybox.vs", "resources/shaders/glsl100/skybox.fs");
|
|
|
|
#endif
|
2019-03-29 22:22:50 +03:00
|
|
|
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT);
|
2017-07-17 01:33:40 +03:00
|
|
|
|
2017-07-21 10:34:09 +03:00
|
|
|
// Load cubemap shader and setup required shader locations
|
2019-05-18 02:24:00 +03:00
|
|
|
#if defined(PLATFORM_DESKTOP)
|
|
|
|
Shader shdrCubemap = LoadShader("resources/shaders/glsl330/cubemap.vs", "resources/shaders/glsl330/cubemap.fs");
|
|
|
|
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
|
|
|
Shader shdrCubemap = LoadShader("resources/shaders/glsl100/cubemap.vs", "resources/shaders/glsl100/cubemap.fs");
|
|
|
|
#endif
|
2019-01-10 13:25:26 +03:00
|
|
|
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2018-06-21 17:48:20 +03:00
|
|
|
// Load HDR panorama (sphere) texture
|
2018-06-21 01:50:03 +03:00
|
|
|
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2018-06-21 17:48:20 +03:00
|
|
|
// 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
|
2019-03-29 22:22:50 +03:00
|
|
|
skybox.materials[0].maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2018-06-21 17:48:20 +03:00
|
|
|
UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated
|
|
|
|
UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2018-06-21 01:50:03 +03:00
|
|
|
SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode
|
2017-07-17 01:33:40 +03:00
|
|
|
|
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Main game loop
|
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
UpdateCamera(&camera); // Update camera
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
|
|
|
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
|
2018-05-04 17:54:05 +03:00
|
|
|
BeginMode3D(camera);
|
2017-07-17 01:33:40 +03:00
|
|
|
|
raymath.h: Use C99 inline semantics
RAYMATH_EXTERN_INLINE was renamed to RAYMATH_HEADER_ONLY, which user code
may define if they want to use it as header-only library. If multiple
files in the same project define RAYMATH_HEADER_ONLY, they might each
have duplicate out-of-line definitions of the same functions.
By default, raymath.h exposes inline definitions, which instructs the
compiler _not_ to generate out-of-line definitons, if out-of-line
definitions are required, those of the file defined with
RAYLIB_IMPLEMENTATION are used instead. There may be only one such file.
In C++ mode, the compiler will select only one out-of-line definition
automatically, so no need to define a RAYLIB_IMPLEMENTATION.
Unfortunately, we have to remove raymath function declaration from
raylib.h as those declarations would lead to duplicate out-of-line
definitions which would yield linker errors. This problem didn't
exist with GNU89 or C++, because there multiple defintions are ok,
but in C99 they aren't.
2018-02-22 04:05:00 +03:00
|
|
|
DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE);
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2017-07-17 01:33:40 +03:00
|
|
|
DrawGrid(10, 1.0f);
|
|
|
|
|
2018-05-04 17:54:05 +03:00
|
|
|
EndMode3D();
|
2017-07-17 01:33:40 +03:00
|
|
|
|
|
|
|
DrawFPS(10, 10);
|
|
|
|
|
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
2018-06-21 17:48:20 +03:00
|
|
|
UnloadModel(skybox); // Unload skybox model (and textures)
|
2017-07-17 01:33:40 +03:00
|
|
|
|
|
|
|
CloseWindow(); // Close window and OpenGL context
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|