|
| 1 | +/******************************************************************************************* |
| 2 | +* |
| 3 | +* raylib-cpp [core] example - Basic window with C++ Modules (adapted for HTML5 platform) |
| 4 | +* |
| 5 | +* This example is prepared to compile for PLATFORM_WEB and PLATFORM_DESKTOP |
| 6 | +* It was adapted from the raylib-cpp [core] example - Basic Window |
| 7 | +* with changes made to allow for compiling with C++ modules |
| 8 | +* To compile it for PLATFORM_WEB just use the --preset DebugWeb or ReleaseWeb in |
| 9 | +* CMakePresets.json |
| 10 | +* |
| 11 | +* This example has been created using raylib-cpp (www.raylib.com) |
| 12 | +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) |
| 13 | +* |
| 14 | +* Copyright (c) 2015 Ramon Santamaria (@raysan5) |
| 15 | +* |
| 16 | +********************************************************************************************/ |
| 17 | + |
| 18 | +#if defined(PLATFORM_WEB) |
| 19 | + #include <emscripten/emscripten.h> |
| 20 | +#endif |
| 21 | + |
| 22 | +import raylib; |
| 23 | + |
| 24 | +using raylib::DrawText; |
| 25 | +using raylib::Color; |
| 26 | + |
| 27 | +//---------------------------------------------------------------------------------- |
| 28 | +// Global Variables Definition |
| 29 | +//---------------------------------------------------------------------------------- |
| 30 | +int screenWidth = 800; |
| 31 | +int screenHeight = 450; |
| 32 | +static raylib::Window window(screenWidth, screenHeight, "raylib-cpp [core] example - basic window"); |
| 33 | + |
| 34 | +//---------------------------------------------------------------------------------- |
| 35 | +// Module Functions Declaration |
| 36 | +//---------------------------------------------------------------------------------- |
| 37 | +void UpdateDrawFrame(); // Update and Draw one frame |
| 38 | + |
| 39 | +//---------------------------------------------------------------------------------- |
| 40 | +// Main Enry Point |
| 41 | +//---------------------------------------------------------------------------------- |
| 42 | +int main() |
| 43 | +{ |
| 44 | + // Initialization |
| 45 | + //-------------------------------------------------------------------------------------- |
| 46 | + // raylib::Window window(screenWidth, screenHeight, "raylib-cpp [core] example - basic window"); |
| 47 | + |
| 48 | +#if defined(PLATFORM_WEB) |
| 49 | + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); |
| 50 | +#else |
| 51 | + window.SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
| 52 | + //-------------------------------------------------------------------------------------- |
| 53 | + |
| 54 | + // Main game loop |
| 55 | + while (!window.ShouldClose()) // Detect window close button or ESC key |
| 56 | + { |
| 57 | + UpdateDrawFrame(); |
| 58 | + } |
| 59 | +#endif |
| 60 | + |
| 61 | + return 0; |
| 62 | +} |
| 63 | + |
| 64 | +//---------------------------------------------------------------------------------- |
| 65 | +// Module Functions Definition |
| 66 | +//---------------------------------------------------------------------------------- |
| 67 | +void UpdateDrawFrame() |
| 68 | +{ |
| 69 | + // Update |
| 70 | + //---------------------------------------------------------------------------------- |
| 71 | + // TODO: Update your variables here |
| 72 | + //---------------------------------------------------------------------------------- |
| 73 | + |
| 74 | + // Draw |
| 75 | + //---------------------------------------------------------------------------------- |
| 76 | + while (window.Drawing()) { |
| 77 | + window.ClearBackground(Color::RayWhite()); |
| 78 | + |
| 79 | + DrawText("Congrats! You created your first raylib-cpp window!", 160, 200, 20, Color::LightGray()); |
| 80 | + } |
| 81 | + //---------------------------------------------------------------------------------- |
| 82 | +} |
0 commit comments