textures_logo_raylib.c 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Texture loading and drawing (adapted for HTML5 platform)
  4. *
  5. * This example has been created using raylib 1.3 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2015 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. #if defined(PLATFORM_WEB)
  13. #include <emscripten/emscripten.h>
  14. #endif
  15. //----------------------------------------------------------------------------------
  16. // Global Variables Definition
  17. //----------------------------------------------------------------------------------
  18. int screenWidth = 800;
  19. int screenHeight = 450;
  20. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  21. Texture2D texture;
  22. //----------------------------------------------------------------------------------
  23. // Module Functions Declaration
  24. //----------------------------------------------------------------------------------
  25. void UpdateDrawFrame(void); // Update and Draw one frame
  26. //----------------------------------------------------------------------------------
  27. // Main Enry Point
  28. //----------------------------------------------------------------------------------
  29. int main()
  30. {
  31. // Initialization
  32. //--------------------------------------------------------------------------------------
  33. InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing");
  34. texture = LoadTexture("resources/raylib_logo.png"); // Texture loading
  35. #if defined(PLATFORM_WEB)
  36. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  37. #else
  38. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  39. //--------------------------------------------------------------------------------------
  40. // Main game loop
  41. while (!WindowShouldClose()) // Detect window close button or ESC key
  42. {
  43. UpdateDrawFrame();
  44. }
  45. #endif
  46. // De-Initialization
  47. //--------------------------------------------------------------------------------------
  48. UnloadTexture(texture); // Texture unloading
  49. CloseWindow(); // Close window and OpenGL context
  50. //--------------------------------------------------------------------------------------
  51. return 0;
  52. }
  53. //----------------------------------------------------------------------------------
  54. // Module Functions Definition
  55. //----------------------------------------------------------------------------------
  56. void UpdateDrawFrame(void)
  57. {
  58. // Update
  59. //----------------------------------------------------------------------------------
  60. // TODO: Update your variables here
  61. //----------------------------------------------------------------------------------
  62. // Draw
  63. //----------------------------------------------------------------------------------
  64. BeginDrawing();
  65. ClearBackground(RAYWHITE);
  66. DrawTexture(texture, screenWidth/2 - texture.width/2,screenHeight/2 - texture.height/2, WHITE);
  67. DrawText("this IS a texture!", 360, 370, 10, GRAY);
  68. EndDrawing();
  69. //----------------------------------------------------------------------------------
  70. }