diff options
| author | Ray <[email protected]> | 2017-10-20 14:09:09 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2017-10-20 14:09:09 +0200 |
| commit | 7447deed40f1deabee659155a30b2d6aa454dafd (patch) | |
| tree | b63cb5b7bc1d850eff4697b2d1d04478ab800ae9 /examples/web/models/models_skybox.c | |
| parent | 1ad4b20e003468434b4e72317c26d04eb8f239ee (diff) | |
| download | raylib.com-7447deed40f1deabee659155a30b2d6aa454dafd.tar.gz raylib.com-7447deed40f1deabee659155a30b2d6aa454dafd.zip | |
Updated examples for web
Diffstat (limited to 'examples/web/models/models_skybox.c')
| -rw-r--r-- | examples/web/models/models_skybox.c | 95 |
1 files changed, 62 insertions, 33 deletions
diff --git a/examples/web/models/models_skybox.c b/examples/web/models/models_skybox.c index 46297e4..8f2bcfd 100644 --- a/examples/web/models/models_skybox.c +++ b/examples/web/models/models_skybox.c @@ -11,21 +11,38 @@ #include "raylib.h" +#if defined(PLATFORM_WEB) + #include <emscripten/emscripten.h> +#endif + +//---------------------------------------------------------------------------------- +// Global Variables Definition +//---------------------------------------------------------------------------------- +int screenWidth = 800; +int screenHeight = 450; + +// Define the camera to look into our 3d world +Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + +Model skybox; + +//---------------------------------------------------------------------------------- +// Module Functions Declaration +//---------------------------------------------------------------------------------- +void UpdateDrawFrame(void); // Update and Draw one frame + +//---------------------------------------------------------------------------------- +// Main Enry Point +//---------------------------------------------------------------------------------- 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 - Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; - // Load skybox model Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); - Model skybox = LoadModelFromMesh(cube); + skybox = LoadModelFromMesh(cube); // Load skybox shader and set required locations // NOTE: Some locations are automatically set at shader loading @@ -43,36 +60,18 @@ int main() SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode - SetTargetFPS(60); // Set our game to run at 60 frames-per-second +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- - + // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key + while (!WindowShouldClose()) // Detect window close button or ESC key { - // Update - //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update camera - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - Begin3dMode(camera); - - DrawModel(skybox, Vector3Zero(), 1.0f, WHITE); - - DrawGrid(10, 1.0f); - - End3dMode(); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- + UpdateDrawFrame(); } +#endif // De-Initialization //-------------------------------------------------------------------------------------- @@ -83,3 +82,33 @@ int main() return 0; } + +//---------------------------------------------------------------------------------- +// Module Functions Definition +//---------------------------------------------------------------------------------- +void UpdateDrawFrame(void) +{ + // Update + //---------------------------------------------------------------------------------- + UpdateCamera(&camera); // Update camera + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + Begin3dMode(camera); + + DrawModel(skybox, Vector3Zero(), 1.0f, WHITE); + + DrawGrid(10, 1.0f); + + End3dMode(); + + DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- +} |
