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-2023 Ramon Santamaria (@raysan5)
11
+ *
12
+ ********************************************************************************************/
13
+
14
+ #include "raylib.h"
15
+
16
+ #define NUM_TEXTURES 3
17
+
18
+ //------------------------------------------------------------------------------------
19
+ // Program main entry point
20
+ //------------------------------------------------------------------------------------
21
+ int main (void )
22
+ {
23
+ // Initialization
24
+ //--------------------------------------------------------------------------------------
25
+ const int screenWidth = 800 ;
26
+ const int screenHeight = 450 ;
27
+
28
+ InitWindow (screenWidth , screenHeight , "raylib [textures] example - texture rotation" );
29
+
30
+ // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
31
+ Image image45 = LoadImage ("resources/raylib_logo.png" );
32
+ Image image90 = LoadImage ("resources/raylib_logo.png" );
33
+ Image imageNeg90 = LoadImage ("resources/raylib_logo.png" );
34
+
35
+ ImageRotate (& image45 , 45 );
36
+ ImageRotate (& image90 , 90 );
37
+ ImageRotate (& imageNeg90 , -90 );
38
+
39
+ Texture2D textures [NUM_TEXTURES ] = { 0 };
40
+
41
+ textures [0 ] = LoadTextureFromImage (image45 );
42
+ textures [1 ] = LoadTextureFromImage (image90 );
43
+ textures [2 ] = LoadTextureFromImage (imageNeg90 );
44
+
45
+ int currentTexture = 0 ;
46
+ //---------------------------------------------------------------------------------------
47
+
48
+ // Main game loop
49
+ while (!WindowShouldClose ()) // Detect window close button or ESC key
50
+ {
51
+ // Update
52
+ //----------------------------------------------------------------------------------
53
+ if (IsMouseButtonPressed (MOUSE_BUTTON_LEFT ) || IsKeyPressed (KEY_RIGHT ))
54
+ {
55
+ currentTexture = (currentTexture + 1 )%NUM_TEXTURES ; // Cycle between the textures
56
+ }
57
+ //----------------------------------------------------------------------------------
58
+
59
+ // Draw
60
+ //----------------------------------------------------------------------------------
61
+ BeginDrawing ();
62
+
63
+ ClearBackground (RAYWHITE );
64
+
65
+ DrawTexture (textures [currentTexture ], screenWidth /2 - textures [currentTexture ].width /2 , screenHeight /2 - textures [currentTexture ].height /2 , WHITE );
66
+
67
+ EndDrawing ();
68
+ //----------------------------------------------------------------------------------
69
+ }
70
+
71
+ // De-Initialization
72
+ //--------------------------------------------------------------------------------------
73
+ for (int i = 0 ; i < NUM_TEXTURES ; i ++ ) UnloadTexture (textures [i ]);
74
+
75
+ CloseWindow (); // Close window and OpenGL context
76
+ //--------------------------------------------------------------------------------------
77
+
78
+ return 0 ;
79
+ }
0 commit comments