You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [textures] example - Image Rotation
  4. *
  5. * Example originally created with raylib 1.0, last time updated with raylib 1.0
  6. *
  7. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  8. * BSD-like license that allows static linking with closed source software
  9. *
  10. * Copyright (c) 2014-2024 Ramon Santamaria (@raysan5)
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. #define NUM_TEXTURES 3
  15. //------------------------------------------------------------------------------------
  16. // Program main entry point
  17. //------------------------------------------------------------------------------------
  18. int main(void)
  19. {
  20. // Initialization
  21. //--------------------------------------------------------------------------------------
  22. const int screenWidth = 800;
  23. const int screenHeight = 450;
  24. InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture rotation");
  25. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  26. Image image45 = LoadImage("resources/raylib_logo.png");
  27. Image image90 = LoadImage("resources/raylib_logo.png");
  28. Image imageNeg90 = LoadImage("resources/raylib_logo.png");
  29. ImageRotate(&image45, 45);
  30. ImageRotate(&image90, 90);
  31. ImageRotate(&imageNeg90, -90);
  32. Texture2D textures[NUM_TEXTURES] = { 0 };
  33. textures[0] = LoadTextureFromImage(image45);
  34. textures[1] = LoadTextureFromImage(image90);
  35. textures[2] = LoadTextureFromImage(imageNeg90);
  36. int currentTexture = 0;
  37. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  38. //---------------------------------------------------------------------------------------
  39. // Main game loop
  40. while (!WindowShouldClose()) // Detect window close button or ESC key
  41. {
  42. // Update
  43. //----------------------------------------------------------------------------------
  44. if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsKeyPressed(KEY_RIGHT))
  45. {
  46. currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures
  47. }
  48. //----------------------------------------------------------------------------------
  49. // Draw
  50. //----------------------------------------------------------------------------------
  51. BeginDrawing();
  52. ClearBackground(RAYWHITE);
  53. DrawTexture(textures[currentTexture], screenWidth/2 - textures[currentTexture].width/2, screenHeight/2 - textures[currentTexture].height/2, WHITE);
  54. DrawText("Press LEFT MOUSE BUTTON to rotate the image clockwise", 250, 420, 10, DARKGRAY);
  55. EndDrawing();
  56. //----------------------------------------------------------------------------------
  57. }
  58. // De-Initialization
  59. //--------------------------------------------------------------------------------------
  60. for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(textures[i]);
  61. CloseWindow(); // Close window and OpenGL context
  62. //--------------------------------------------------------------------------------------
  63. return 0;
  64. }