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"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
int screenWidth = 800;
|
|
|
|
int screenHeight = 450;
|
|
|
|
|
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
|
|
|
|
|
|
|
|
// Define the camera to look into our 3d world
|
2018-04-11 11:13:00 +03:00
|
|
|
Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
2017-07-17 01:33:40 +03:00
|
|
|
|
2017-07-21 10:34:09 +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);
|
|
|
|
|
|
|
|
// Load skybox shader and set required locations
|
|
|
|
// NOTE: Some locations are automatically set at shader loading
|
2017-07-17 01:33:40 +03:00
|
|
|
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
|
2017-07-19 11:09:34 +03:00
|
|
|
SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, 1);
|
2017-07-17 01:33:40 +03:00
|
|
|
|
2017-07-21 10:34:09 +03:00
|
|
|
// Load cubemap shader and setup required shader locations
|
|
|
|
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs");
|
2017-07-21 18:17:37 +03:00
|
|
|
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1);
|
2017-07-21 10:34:09 +03:00
|
|
|
|
2018-06-21 01:50:03 +03:00
|
|
|
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
|
2017-07-21 10:34:09 +03:00
|
|
|
skybox.material.maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
|
|
|
|
|
|
|
|
UnloadShader(shdrCubemap); // Cubemap generation shader not required any more
|
|
|
|
|
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);
|
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
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
UnloadModel(skybox); // Unload skybox model
|
|
|
|
|
|
|
|
CloseWindow(); // Close window and OpenGL context
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|