textures_image_rotate.c 3.3 KB

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