2
0

web_basic_window.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*******************************************************************************************
  2. *
  3. * raylib [others] example - basic window
  4. *
  5. * This example has been adapted to compile for PLATFORM_WEB and PLATFORM_DESKTOP
  6. * As you will notice, code structure is slightly different to the other examples
  7. *
  8. * Example complexity rating: [★☆☆☆] 1/4
  9. *
  10. * Example originally created with raylib 1.3, last time updated with raylib 5.5
  11. *
  12. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  13. * BSD-like license that allows static linking with closed source software
  14. *
  15. * Copyright (c) 2015-2025 Ramon Santamaria (@raysan5)
  16. *
  17. ********************************************************************************************/
  18. #include "raylib.h"
  19. #if defined(PLATFORM_WEB)
  20. #include <emscripten/emscripten.h>
  21. #endif
  22. //----------------------------------------------------------------------------------
  23. // Global Variables Definition
  24. //----------------------------------------------------------------------------------
  25. int screenWidth = 800;
  26. 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 [others] example - web 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. }