Skip to content

Commit e465ed0

Browse files
authored
Added ImageRotate (raysan5#3078)
* Added ImageRotate * Quick rename of the example * Update ImageRotate by changing doubles to floats and checking code convention * Update API
1 parent bf69b38 commit e465ed0

File tree

12 files changed

+429
-247
lines changed

12 files changed

+429
-247
lines changed

examples/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ TEXTURES = \
453453
textures/textures_image_generation \
454454
textures/textures_image_loading \
455455
textures/textures_image_processing \
456+
textures/textures_image_rotate \
456457
textures/textures_image_text \
457458
textures/textures_to_image \
458459
textures/textures_raw_data \
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
}
23.5 KB
Loading

parser/output/raylib_api.json

+15
Original file line numberDiff line numberDiff line change
@@ -6757,6 +6757,21 @@
67576757
}
67586758
]
67596759
},
6760+
{
6761+
"name": "ImageRotate",
6762+
"description": "Rotate image by input angle in degrees (-359 to 359) ",
6763+
"returnType": "void",
6764+
"params": [
6765+
{
6766+
"type": "Image *",
6767+
"name": "image"
6768+
},
6769+
{
6770+
"type": "int",
6771+
"name": "degrees"
6772+
}
6773+
]
6774+
},
67606775
{
67616776
"name": "ImageRotateCW",
67626777
"description": "Rotate image clockwise 90deg",

parser/output/raylib_api.lua

+9
Original file line numberDiff line numberDiff line change
@@ -5266,6 +5266,15 @@ return {
52665266
{type = "Image *", name = "image"}
52675267
}
52685268
},
5269+
{
5270+
name = "ImageRotate",
5271+
description = "Rotate image by input angle in degrees (-359 to 359) ",
5272+
returnType = "void",
5273+
params = {
5274+
{type = "Image *", name = "image"},
5275+
{type = "int", name = "degrees"}
5276+
}
5277+
},
52695278
{
52705279
name = "ImageRotateCW",
52715280
description = "Rotate image clockwise 90deg",

0 commit comments

Comments
 (0)