core_basic_window_web.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Basic window (adapted for HTML5 platform)
  4. *
  5. * NOTE: This example is prepared to compile for PLATFORM_WEB, and PLATFORM_DESKTOP
  6. * As you will notice, code structure is slightly diferent to the other examples...
  7. * To compile it for PLATFORM_WEB just uncomment #define PLATFORM_WEB at beginning
  8. *
  9. * Example originally created with raylib 1.3, last time updated with raylib 1.3
  10. *
  11. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  12. * BSD-like license that allows static linking with closed source software
  13. *
  14. * Copyright (c) 2015-2023 Ramon Santamaria (@raysan5)
  15. *
  16. ********************************************************************************************/
  17. #include "raylib.h"
  18. //#define PLATFORM_WEB
  19. #if defined(PLATFORM_WEB)
  20. #include <emscripten/emscripten.h>
  21. #endif
  22. //----------------------------------------------------------------------------------
  23. // Global Variables Definition
  24. //----------------------------------------------------------------------------------
  25. const int screenWidth = 800;
  26. const int screenHeight = 450;
  27. //----------------------------------------------------------------------------------
  28. // Module functions declaration
  29. //----------------------------------------------------------------------------------
  30. void UpdateDrawFrame(void); // Update and Draw one frame
  31. //------------------------------------------------------------------------------------
  32. // Program main entry point
  33. //------------------------------------------------------------------------------------
  34. int main(void)
  35. {
  36. // Initialization
  37. //--------------------------------------------------------------------------------------
  38. InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
  39. #if defined(PLATFORM_WEB)
  40. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  41. #else
  42. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  43. //--------------------------------------------------------------------------------------
  44. // Main game loop
  45. while (!WindowShouldClose()) // Detect window close button or ESC key
  46. {
  47. UpdateDrawFrame();
  48. }
  49. #endif
  50. // De-Initialization
  51. //--------------------------------------------------------------------------------------
  52. CloseWindow(); // Close window and OpenGL context
  53. //--------------------------------------------------------------------------------------
  54. return 0;
  55. }
  56. //----------------------------------------------------------------------------------
  57. // Module Functions Definition
  58. //----------------------------------------------------------------------------------
  59. void UpdateDrawFrame(void)
  60. {
  61. // Update
  62. //----------------------------------------------------------------------------------
  63. // TODO: Update your variables here
  64. //----------------------------------------------------------------------------------
  65. // Draw
  66. //----------------------------------------------------------------------------------
  67. BeginDrawing();
  68. ClearBackground(RAYWHITE);
  69. DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
  70. EndDrawing();
  71. //----------------------------------------------------------------------------------
  72. }