diff options
author | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
commit | 6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch) | |
tree | 34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/examples/renderer | |
parent | 8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff) |
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/examples/renderer')
57 files changed, 1838 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/01-clear/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/01-clear/README.txt new file mode 100644 index 0000000..ce9ef81 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/01-clear/README.txt | |||
@@ -0,0 +1,3 @@ | |||
1 | This example code creates an SDL window and renderer, and then clears the | ||
2 | window to a different color every frame, so you'll effectively get a window | ||
3 | that's smoothly fading between colors. | ||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/01-clear/clear.c b/src/contrib/SDL-3.2.20/examples/renderer/01-clear/clear.c new file mode 100644 index 0000000..5b2b7dc --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/01-clear/clear.c | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | * This example code creates an SDL window and renderer, and then clears the | ||
3 | * window to a different color every frame, so you'll effectively get a window | ||
4 | * that's smoothly fading between colors. | ||
5 | * | ||
6 | * This code is public domain. Feel free to use it for any purpose! | ||
7 | */ | ||
8 | |||
9 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
10 | #include <SDL3/SDL.h> | ||
11 | #include <SDL3/SDL_main.h> | ||
12 | |||
13 | /* We will use this renderer to draw into this window every frame. */ | ||
14 | static SDL_Window *window = NULL; | ||
15 | static SDL_Renderer *renderer = NULL; | ||
16 | |||
17 | /* This function runs once at startup. */ | ||
18 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
19 | { | ||
20 | SDL_SetAppMetadata("Example Renderer Clear", "1.0", "com.example.renderer-clear"); | ||
21 | |||
22 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
23 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
24 | return SDL_APP_FAILURE; | ||
25 | } | ||
26 | |||
27 | if (!SDL_CreateWindowAndRenderer("examples/renderer/clear", 640, 480, 0, &window, &renderer)) { | ||
28 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
29 | return SDL_APP_FAILURE; | ||
30 | } | ||
31 | |||
32 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
33 | } | ||
34 | |||
35 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
36 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
37 | { | ||
38 | if (event->type == SDL_EVENT_QUIT) { | ||
39 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
40 | } | ||
41 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
42 | } | ||
43 | |||
44 | /* This function runs once per frame, and is the heart of the program. */ | ||
45 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
46 | { | ||
47 | const double now = ((double)SDL_GetTicks()) / 1000.0; /* convert from milliseconds to seconds. */ | ||
48 | /* choose the color for the frame we will draw. The sine wave trick makes it fade between colors smoothly. */ | ||
49 | const float red = (float) (0.5 + 0.5 * SDL_sin(now)); | ||
50 | const float green = (float) (0.5 + 0.5 * SDL_sin(now + SDL_PI_D * 2 / 3)); | ||
51 | const float blue = (float) (0.5 + 0.5 * SDL_sin(now + SDL_PI_D * 4 / 3)); | ||
52 | SDL_SetRenderDrawColorFloat(renderer, red, green, blue, SDL_ALPHA_OPAQUE_FLOAT); /* new color, full alpha. */ | ||
53 | |||
54 | /* clear the window to the draw color. */ | ||
55 | SDL_RenderClear(renderer); | ||
56 | |||
57 | /* put the newly-cleared rendering on the screen. */ | ||
58 | SDL_RenderPresent(renderer); | ||
59 | |||
60 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
61 | } | ||
62 | |||
63 | /* This function runs once at shutdown. */ | ||
64 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
65 | { | ||
66 | /* SDL will clean up the window/renderer for us. */ | ||
67 | } | ||
68 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/01-clear/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/01-clear/onmouseover.webp new file mode 100644 index 0000000..a0062fe --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/01-clear/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/01-clear/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/01-clear/thumbnail.png new file mode 100644 index 0000000..b255675 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/01-clear/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/02-primitives/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/02-primitives/README.txt new file mode 100644 index 0000000..82da8e5 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/02-primitives/README.txt | |||
@@ -0,0 +1,7 @@ | |||
1 | This example creates an SDL window and renderer, and then draws some lines, | ||
2 | rectangles and points to it every frame. | ||
3 | |||
4 | This is just a quick overview of simple drawing primitives; futher examples | ||
5 | will explore them in more detail. | ||
6 | |||
7 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/02-primitives/primitives.c b/src/contrib/SDL-3.2.20/examples/renderer/02-primitives/primitives.c new file mode 100644 index 0000000..5cfd731 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/02-primitives/primitives.c | |||
@@ -0,0 +1,95 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some lines, | ||
3 | * rectangles and points to it every frame. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | static SDL_FPoint points[500]; | ||
16 | |||
17 | /* This function runs once at startup. */ | ||
18 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
19 | { | ||
20 | int i; | ||
21 | |||
22 | SDL_SetAppMetadata("Example Renderer Primitives", "1.0", "com.example.renderer-primitives"); | ||
23 | |||
24 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
25 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
26 | return SDL_APP_FAILURE; | ||
27 | } | ||
28 | |||
29 | if (!SDL_CreateWindowAndRenderer("examples/renderer/primitives", 640, 480, 0, &window, &renderer)) { | ||
30 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
31 | return SDL_APP_FAILURE; | ||
32 | } | ||
33 | |||
34 | /* set up some random points */ | ||
35 | for (i = 0; i < SDL_arraysize(points); i++) { | ||
36 | points[i].x = (SDL_randf() * 440.0f) + 100.0f; | ||
37 | points[i].y = (SDL_randf() * 280.0f) + 100.0f; | ||
38 | } | ||
39 | |||
40 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
41 | } | ||
42 | |||
43 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
44 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
45 | { | ||
46 | if (event->type == SDL_EVENT_QUIT) { | ||
47 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
48 | } | ||
49 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
50 | } | ||
51 | |||
52 | /* This function runs once per frame, and is the heart of the program. */ | ||
53 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
54 | { | ||
55 | SDL_FRect rect; | ||
56 | |||
57 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
58 | SDL_SetRenderDrawColor(renderer, 33, 33, 33, SDL_ALPHA_OPAQUE); /* dark gray, full alpha */ | ||
59 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
60 | |||
61 | /* draw a filled rectangle in the middle of the canvas. */ | ||
62 | SDL_SetRenderDrawColor(renderer, 0, 0, 255, SDL_ALPHA_OPAQUE); /* blue, full alpha */ | ||
63 | rect.x = rect.y = 100; | ||
64 | rect.w = 440; | ||
65 | rect.h = 280; | ||
66 | SDL_RenderFillRect(renderer, &rect); | ||
67 | |||
68 | /* draw some points across the canvas. */ | ||
69 | SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE); /* red, full alpha */ | ||
70 | SDL_RenderPoints(renderer, points, SDL_arraysize(points)); | ||
71 | |||
72 | /* draw a unfilled rectangle in-set a little bit. */ | ||
73 | SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE); /* green, full alpha */ | ||
74 | rect.x += 30; | ||
75 | rect.y += 30; | ||
76 | rect.w -= 60; | ||
77 | rect.h -= 60; | ||
78 | SDL_RenderRect(renderer, &rect); | ||
79 | |||
80 | /* draw two lines in an X across the whole canvas. */ | ||
81 | SDL_SetRenderDrawColor(renderer, 255, 255, 0, SDL_ALPHA_OPAQUE); /* yellow, full alpha */ | ||
82 | SDL_RenderLine(renderer, 0, 0, 640, 480); | ||
83 | SDL_RenderLine(renderer, 0, 480, 640, 0); | ||
84 | |||
85 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
86 | |||
87 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
88 | } | ||
89 | |||
90 | /* This function runs once at shutdown. */ | ||
91 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
92 | { | ||
93 | /* SDL will clean up the window/renderer for us. */ | ||
94 | } | ||
95 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/02-primitives/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/02-primitives/thumbnail.png new file mode 100644 index 0000000..4ddf2ab --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/02-primitives/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/03-lines/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/03-lines/README.txt new file mode 100644 index 0000000..4abeab6 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/03-lines/README.txt | |||
@@ -0,0 +1,3 @@ | |||
1 | This example creates an SDL window and renderer, and then draws a something | ||
2 | roughly like a Christmas tree with nothing but lines, every frame. | ||
3 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/03-lines/lines.c b/src/contrib/SDL-3.2.20/examples/renderer/03-lines/lines.c new file mode 100644 index 0000000..54f7eb1 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/03-lines/lines.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some lines | ||
3 | * to it every frame. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | |||
16 | /* This function runs once at startup. */ | ||
17 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
18 | { | ||
19 | SDL_SetAppMetadata("Example Renderer Lines", "1.0", "com.example.renderer-lines"); | ||
20 | |||
21 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
22 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
23 | return SDL_APP_FAILURE; | ||
24 | } | ||
25 | |||
26 | if (!SDL_CreateWindowAndRenderer("examples/renderer/lines", 640, 480, 0, &window, &renderer)) { | ||
27 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
28 | return SDL_APP_FAILURE; | ||
29 | } | ||
30 | |||
31 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
32 | } | ||
33 | |||
34 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
35 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
36 | { | ||
37 | if (event->type == SDL_EVENT_QUIT) { | ||
38 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
39 | } | ||
40 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
41 | } | ||
42 | |||
43 | /* This function runs once per frame, and is the heart of the program. */ | ||
44 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
45 | { | ||
46 | int i; | ||
47 | |||
48 | /* Lines (line segments, really) are drawn in terms of points: a set of | ||
49 | X and Y coordinates, one set for each end of the line. | ||
50 | (0, 0) is the top left of the window, and larger numbers go down | ||
51 | and to the right. This isn't how geometry works, but this is pretty | ||
52 | standard in 2D graphics. */ | ||
53 | static const SDL_FPoint line_points[] = { | ||
54 | { 100, 354 }, { 220, 230 }, { 140, 230 }, { 320, 100 }, { 500, 230 }, | ||
55 | { 420, 230 }, { 540, 354 }, { 400, 354 }, { 100, 354 } | ||
56 | }; | ||
57 | |||
58 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
59 | SDL_SetRenderDrawColor(renderer, 100, 100, 100, SDL_ALPHA_OPAQUE); /* grey, full alpha */ | ||
60 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
61 | |||
62 | /* You can draw lines, one at a time, like these brown ones... */ | ||
63 | SDL_SetRenderDrawColor(renderer, 127, 49, 32, SDL_ALPHA_OPAQUE); | ||
64 | SDL_RenderLine(renderer, 240, 450, 400, 450); | ||
65 | SDL_RenderLine(renderer, 240, 356, 400, 356); | ||
66 | SDL_RenderLine(renderer, 240, 356, 240, 450); | ||
67 | SDL_RenderLine(renderer, 400, 356, 400, 450); | ||
68 | |||
69 | /* You can also draw a series of connected lines in a single batch... */ | ||
70 | SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE); | ||
71 | SDL_RenderLines(renderer, line_points, SDL_arraysize(line_points)); | ||
72 | |||
73 | /* here's a bunch of lines drawn out from a center point in a circle. */ | ||
74 | /* we randomize the color of each line, so it functions as animation. */ | ||
75 | for (i = 0; i < 360; i++) { | ||
76 | const float size = 30.0f; | ||
77 | const float x = 320.0f; | ||
78 | const float y = 95.0f - (size / 2.0f); | ||
79 | SDL_SetRenderDrawColor(renderer, SDL_rand(256), SDL_rand(256), SDL_rand(256), SDL_ALPHA_OPAQUE); | ||
80 | SDL_RenderLine(renderer, x, y, x + SDL_sinf((float) i) * size, y + SDL_cosf((float) i) * size); | ||
81 | } | ||
82 | |||
83 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
84 | |||
85 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
86 | } | ||
87 | |||
88 | /* This function runs once at shutdown. */ | ||
89 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
90 | { | ||
91 | /* SDL will clean up the window/renderer for us. */ | ||
92 | } | ||
93 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/03-lines/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/03-lines/onmouseover.webp new file mode 100644 index 0000000..5d3b3fc --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/03-lines/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/03-lines/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/03-lines/thumbnail.png new file mode 100644 index 0000000..9d0ff10 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/03-lines/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/04-points/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/04-points/README.txt new file mode 100644 index 0000000..00e9419 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/04-points/README.txt | |||
@@ -0,0 +1,3 @@ | |||
1 | This example creates an SDL window and renderer, and then draws a bunch of | ||
2 | single points, moving across the screen. | ||
3 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/04-points/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/04-points/onmouseover.webp new file mode 100644 index 0000000..04582da --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/04-points/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/04-points/points.c b/src/contrib/SDL-3.2.20/examples/renderer/04-points/points.c new file mode 100644 index 0000000..b7b5c21 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/04-points/points.c | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some points | ||
3 | * to it every frame. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | static Uint64 last_time = 0; | ||
16 | |||
17 | #define WINDOW_WIDTH 640 | ||
18 | #define WINDOW_HEIGHT 480 | ||
19 | |||
20 | #define NUM_POINTS 500 | ||
21 | #define MIN_PIXELS_PER_SECOND 30 /* move at least this many pixels per second. */ | ||
22 | #define MAX_PIXELS_PER_SECOND 60 /* move this many pixels per second at most. */ | ||
23 | |||
24 | /* (track everything as parallel arrays instead of a array of structs, | ||
25 | so we can pass the coordinates to the renderer in a single function call.) */ | ||
26 | |||
27 | /* Points are plotted as a set of X and Y coordinates. | ||
28 | (0, 0) is the top left of the window, and larger numbers go down | ||
29 | and to the right. This isn't how geometry works, but this is pretty | ||
30 | standard in 2D graphics. */ | ||
31 | static SDL_FPoint points[NUM_POINTS]; | ||
32 | static float point_speeds[NUM_POINTS]; | ||
33 | |||
34 | /* This function runs once at startup. */ | ||
35 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
36 | { | ||
37 | int i; | ||
38 | |||
39 | SDL_SetAppMetadata("Example Renderer Points", "1.0", "com.example.renderer-points"); | ||
40 | |||
41 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
42 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
43 | return SDL_APP_FAILURE; | ||
44 | } | ||
45 | |||
46 | if (!SDL_CreateWindowAndRenderer("examples/renderer/points", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
47 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
48 | return SDL_APP_FAILURE; | ||
49 | } | ||
50 | |||
51 | /* set up the data for a bunch of points. */ | ||
52 | for (i = 0; i < SDL_arraysize(points); i++) { | ||
53 | points[i].x = SDL_randf() * ((float) WINDOW_WIDTH); | ||
54 | points[i].y = SDL_randf() * ((float) WINDOW_HEIGHT); | ||
55 | point_speeds[i] = MIN_PIXELS_PER_SECOND + (SDL_randf() * (MAX_PIXELS_PER_SECOND - MIN_PIXELS_PER_SECOND)); | ||
56 | } | ||
57 | |||
58 | last_time = SDL_GetTicks(); | ||
59 | |||
60 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
61 | } | ||
62 | |||
63 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
64 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
65 | { | ||
66 | if (event->type == SDL_EVENT_QUIT) { | ||
67 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
68 | } | ||
69 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
70 | } | ||
71 | |||
72 | /* This function runs once per frame, and is the heart of the program. */ | ||
73 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
74 | { | ||
75 | const Uint64 now = SDL_GetTicks(); | ||
76 | const float elapsed = ((float) (now - last_time)) / 1000.0f; /* seconds since last iteration */ | ||
77 | int i; | ||
78 | |||
79 | /* let's move all our points a little for a new frame. */ | ||
80 | for (i = 0; i < SDL_arraysize(points); i++) { | ||
81 | const float distance = elapsed * point_speeds[i]; | ||
82 | points[i].x += distance; | ||
83 | points[i].y += distance; | ||
84 | if ((points[i].x >= WINDOW_WIDTH) || (points[i].y >= WINDOW_HEIGHT)) { | ||
85 | /* off the screen; restart it elsewhere! */ | ||
86 | if (SDL_rand(2)) { | ||
87 | points[i].x = SDL_randf() * ((float) WINDOW_WIDTH); | ||
88 | points[i].y = 0.0f; | ||
89 | } else { | ||
90 | points[i].x = 0.0f; | ||
91 | points[i].y = SDL_randf() * ((float) WINDOW_HEIGHT); | ||
92 | } | ||
93 | point_speeds[i] = MIN_PIXELS_PER_SECOND + (SDL_randf() * (MAX_PIXELS_PER_SECOND - MIN_PIXELS_PER_SECOND)); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | last_time = now; | ||
98 | |||
99 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
100 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ | ||
101 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
102 | SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); /* white, full alpha */ | ||
103 | SDL_RenderPoints(renderer, points, SDL_arraysize(points)); /* draw all the points! */ | ||
104 | |||
105 | /* You can also draw single points with SDL_RenderPoint(), but it's | ||
106 | cheaper (sometimes significantly so) to do them all at once. */ | ||
107 | |||
108 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
109 | |||
110 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
111 | } | ||
112 | |||
113 | /* This function runs once at shutdown. */ | ||
114 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
115 | { | ||
116 | /* SDL will clean up the window/renderer for us. */ | ||
117 | } | ||
118 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/04-points/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/04-points/thumbnail.png new file mode 100644 index 0000000..5627113 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/04-points/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/README.txt new file mode 100644 index 0000000..26613c7 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/README.txt | |||
@@ -0,0 +1,3 @@ | |||
1 | This example creates an SDL window and renderer, and then draws a few | ||
2 | rectangles that change size each frame. | ||
3 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/onmouseover.webp new file mode 100644 index 0000000..cdfd376 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/rectangles.c b/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/rectangles.c new file mode 100644 index 0000000..3aa7242 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/rectangles.c | |||
@@ -0,0 +1,112 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some | ||
3 | * rectangles to it every frame. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | |||
16 | #define WINDOW_WIDTH 640 | ||
17 | #define WINDOW_HEIGHT 480 | ||
18 | |||
19 | /* This function runs once at startup. */ | ||
20 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
21 | { | ||
22 | SDL_SetAppMetadata("Example Renderer Rectangles", "1.0", "com.example.renderer-rectangles"); | ||
23 | |||
24 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
25 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
26 | return SDL_APP_FAILURE; | ||
27 | } | ||
28 | |||
29 | if (!SDL_CreateWindowAndRenderer("examples/renderer/rectangles", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
30 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
31 | return SDL_APP_FAILURE; | ||
32 | } | ||
33 | |||
34 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
35 | } | ||
36 | |||
37 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
38 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
39 | { | ||
40 | if (event->type == SDL_EVENT_QUIT) { | ||
41 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
42 | } | ||
43 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
44 | } | ||
45 | |||
46 | /* This function runs once per frame, and is the heart of the program. */ | ||
47 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
48 | { | ||
49 | SDL_FRect rects[16]; | ||
50 | const Uint64 now = SDL_GetTicks(); | ||
51 | int i; | ||
52 | |||
53 | /* we'll have the rectangles grow and shrink over a few seconds. */ | ||
54 | const float direction = ((now % 2000) >= 1000) ? 1.0f : -1.0f; | ||
55 | const float scale = ((float) (((int) (now % 1000)) - 500) / 500.0f) * direction; | ||
56 | |||
57 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
58 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ | ||
59 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
60 | |||
61 | /* Rectangles are comprised of set of X and Y coordinates, plus width and | ||
62 | height. (0, 0) is the top left of the window, and larger numbers go | ||
63 | down and to the right. This isn't how geometry works, but this is | ||
64 | pretty standard in 2D graphics. */ | ||
65 | |||
66 | /* Let's draw a single rectangle (square, really). */ | ||
67 | rects[0].x = rects[0].y = 100; | ||
68 | rects[0].w = rects[0].h = 100 + (100 * scale); | ||
69 | SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE); /* red, full alpha */ | ||
70 | SDL_RenderRect(renderer, &rects[0]); | ||
71 | |||
72 | /* Now let's draw several rectangles with one function call. */ | ||
73 | for (i = 0; i < 3; i++) { | ||
74 | const float size = (i+1) * 50.0f; | ||
75 | rects[i].w = rects[i].h = size + (size * scale); | ||
76 | rects[i].x = (WINDOW_WIDTH - rects[i].w) / 2; /* center it. */ | ||
77 | rects[i].y = (WINDOW_HEIGHT - rects[i].h) / 2; /* center it. */ | ||
78 | } | ||
79 | SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE); /* green, full alpha */ | ||
80 | SDL_RenderRects(renderer, rects, 3); /* draw three rectangles at once */ | ||
81 | |||
82 | /* those were rectangle _outlines_, really. You can also draw _filled_ rectangles! */ | ||
83 | rects[0].x = 400; | ||
84 | rects[0].y = 50; | ||
85 | rects[0].w = 100 + (100 * scale); | ||
86 | rects[0].h = 50 + (50 * scale); | ||
87 | SDL_SetRenderDrawColor(renderer, 0, 0, 255, SDL_ALPHA_OPAQUE); /* blue, full alpha */ | ||
88 | SDL_RenderFillRect(renderer, &rects[0]); | ||
89 | |||
90 | /* ...and also fill a bunch of rectangles at once... */ | ||
91 | for (i = 0; i < SDL_arraysize(rects); i++) { | ||
92 | const float w = (float) (WINDOW_WIDTH / SDL_arraysize(rects)); | ||
93 | const float h = i * 8.0f; | ||
94 | rects[i].x = i * w; | ||
95 | rects[i].y = WINDOW_HEIGHT - h; | ||
96 | rects[i].w = w; | ||
97 | rects[i].h = h; | ||
98 | } | ||
99 | SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); /* white, full alpha */ | ||
100 | SDL_RenderFillRects(renderer, rects, SDL_arraysize(rects)); | ||
101 | |||
102 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
103 | |||
104 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
105 | } | ||
106 | |||
107 | /* This function runs once at shutdown. */ | ||
108 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
109 | { | ||
110 | /* SDL will clean up the window/renderer for us. */ | ||
111 | } | ||
112 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/thumbnail.png new file mode 100644 index 0000000..64e6688 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/05-rectangles/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/06-textures/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/06-textures/README.txt new file mode 100644 index 0000000..21c3f0b --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/06-textures/README.txt | |||
@@ -0,0 +1,3 @@ | |||
1 | This example creates an SDL window and renderer, loads a texture from a | ||
2 | .bmp file, and then draws it a few times each frame. | ||
3 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/06-textures/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/06-textures/onmouseover.webp new file mode 100644 index 0000000..467afd8 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/06-textures/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/06-textures/textures.c b/src/contrib/SDL-3.2.20/examples/renderer/06-textures/textures.c new file mode 100644 index 0000000..f4ad707 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/06-textures/textures.c | |||
@@ -0,0 +1,127 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some | ||
3 | * textures to it every frame. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | static SDL_Texture *texture = NULL; | ||
16 | static int texture_width = 0; | ||
17 | static int texture_height = 0; | ||
18 | |||
19 | #define WINDOW_WIDTH 640 | ||
20 | #define WINDOW_HEIGHT 480 | ||
21 | |||
22 | /* This function runs once at startup. */ | ||
23 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
24 | { | ||
25 | SDL_Surface *surface = NULL; | ||
26 | char *bmp_path = NULL; | ||
27 | |||
28 | SDL_SetAppMetadata("Example Renderer Textures", "1.0", "com.example.renderer-textures"); | ||
29 | |||
30 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
31 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
32 | return SDL_APP_FAILURE; | ||
33 | } | ||
34 | |||
35 | if (!SDL_CreateWindowAndRenderer("examples/renderer/textures", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
36 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
37 | return SDL_APP_FAILURE; | ||
38 | } | ||
39 | |||
40 | /* Textures are pixel data that we upload to the video hardware for fast drawing. Lots of 2D | ||
41 | engines refer to these as "sprites." We'll do a static texture (upload once, draw many | ||
42 | times) with data from a bitmap file. */ | ||
43 | |||
44 | /* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access. | ||
45 | Load a .bmp into a surface, move it to a texture from there. */ | ||
46 | SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */ | ||
47 | surface = SDL_LoadBMP(bmp_path); | ||
48 | if (!surface) { | ||
49 | SDL_Log("Couldn't load bitmap: %s", SDL_GetError()); | ||
50 | return SDL_APP_FAILURE; | ||
51 | } | ||
52 | |||
53 | SDL_free(bmp_path); /* done with this, the file is loaded. */ | ||
54 | |||
55 | texture_width = surface->w; | ||
56 | texture_height = surface->h; | ||
57 | |||
58 | texture = SDL_CreateTextureFromSurface(renderer, surface); | ||
59 | if (!texture) { | ||
60 | SDL_Log("Couldn't create static texture: %s", SDL_GetError()); | ||
61 | return SDL_APP_FAILURE; | ||
62 | } | ||
63 | |||
64 | SDL_DestroySurface(surface); /* done with this, the texture has a copy of the pixels now. */ | ||
65 | |||
66 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
67 | } | ||
68 | |||
69 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
70 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
71 | { | ||
72 | if (event->type == SDL_EVENT_QUIT) { | ||
73 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
74 | } | ||
75 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
76 | } | ||
77 | |||
78 | /* This function runs once per frame, and is the heart of the program. */ | ||
79 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
80 | { | ||
81 | SDL_FRect dst_rect; | ||
82 | const Uint64 now = SDL_GetTicks(); | ||
83 | |||
84 | /* we'll have some textures move around over a few seconds. */ | ||
85 | const float direction = ((now % 2000) >= 1000) ? 1.0f : -1.0f; | ||
86 | const float scale = ((float) (((int) (now % 1000)) - 500) / 500.0f) * direction; | ||
87 | |||
88 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
89 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ | ||
90 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
91 | |||
92 | /* Just draw the static texture a few times. You can think of it like a | ||
93 | stamp, there isn't a limit to the number of times you can draw with it. */ | ||
94 | |||
95 | /* top left */ | ||
96 | dst_rect.x = (100.0f * scale); | ||
97 | dst_rect.y = 0.0f; | ||
98 | dst_rect.w = (float) texture_width; | ||
99 | dst_rect.h = (float) texture_height; | ||
100 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
101 | |||
102 | /* center this one. */ | ||
103 | dst_rect.x = ((float) (WINDOW_WIDTH - texture_width)) / 2.0f; | ||
104 | dst_rect.y = ((float) (WINDOW_HEIGHT - texture_height)) / 2.0f; | ||
105 | dst_rect.w = (float) texture_width; | ||
106 | dst_rect.h = (float) texture_height; | ||
107 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
108 | |||
109 | /* bottom right. */ | ||
110 | dst_rect.x = ((float) (WINDOW_WIDTH - texture_width)) - (100.0f * scale); | ||
111 | dst_rect.y = (float) (WINDOW_HEIGHT - texture_height); | ||
112 | dst_rect.w = (float) texture_width; | ||
113 | dst_rect.h = (float) texture_height; | ||
114 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
115 | |||
116 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
117 | |||
118 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
119 | } | ||
120 | |||
121 | /* This function runs once at shutdown. */ | ||
122 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
123 | { | ||
124 | SDL_DestroyTexture(texture); | ||
125 | /* SDL will clean up the window/renderer for us. */ | ||
126 | } | ||
127 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/06-textures/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/06-textures/thumbnail.png new file mode 100644 index 0000000..b33ba31 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/06-textures/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/README.txt new file mode 100644 index 0000000..c250571 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/README.txt | |||
@@ -0,0 +1,3 @@ | |||
1 | This example creates an SDL window and renderer, then a streaming texture that | ||
2 | it will update every frame before drawing it to the screen. | ||
3 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/onmouseover.webp new file mode 100644 index 0000000..7c29693 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/streaming-textures.c b/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/streaming-textures.c new file mode 100644 index 0000000..bf309bc --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/streaming-textures.c | |||
@@ -0,0 +1,109 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws a streaming | ||
3 | * texture to it every frame. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | static SDL_Texture *texture = NULL; | ||
16 | |||
17 | #define TEXTURE_SIZE 150 | ||
18 | |||
19 | #define WINDOW_WIDTH 640 | ||
20 | #define WINDOW_HEIGHT 480 | ||
21 | |||
22 | /* This function runs once at startup. */ | ||
23 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
24 | { | ||
25 | SDL_SetAppMetadata("Example Renderer Streaming Textures", "1.0", "com.example.renderer-streaming-textures"); | ||
26 | |||
27 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
28 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
29 | return SDL_APP_FAILURE; | ||
30 | } | ||
31 | |||
32 | if (!SDL_CreateWindowAndRenderer("examples/renderer/streaming-textures", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
33 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
34 | return SDL_APP_FAILURE; | ||
35 | } | ||
36 | |||
37 | texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, TEXTURE_SIZE, TEXTURE_SIZE); | ||
38 | if (!texture) { | ||
39 | SDL_Log("Couldn't create streaming texture: %s", SDL_GetError()); | ||
40 | return SDL_APP_FAILURE; | ||
41 | } | ||
42 | |||
43 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
44 | } | ||
45 | |||
46 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
47 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
48 | { | ||
49 | if (event->type == SDL_EVENT_QUIT) { | ||
50 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
51 | } | ||
52 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
53 | } | ||
54 | |||
55 | /* This function runs once per frame, and is the heart of the program. */ | ||
56 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
57 | { | ||
58 | SDL_FRect dst_rect; | ||
59 | const Uint64 now = SDL_GetTicks(); | ||
60 | SDL_Surface *surface = NULL; | ||
61 | |||
62 | /* we'll have some color move around over a few seconds. */ | ||
63 | const float direction = ((now % 2000) >= 1000) ? 1.0f : -1.0f; | ||
64 | const float scale = ((float) (((int) (now % 1000)) - 500) / 500.0f) * direction; | ||
65 | |||
66 | /* To update a streaming texture, you need to lock it first. This gets you access to the pixels. | ||
67 | Note that this is considered a _write-only_ operation: the buffer you get from locking | ||
68 | might not acutally have the existing contents of the texture, and you have to write to every | ||
69 | locked pixel! */ | ||
70 | |||
71 | /* You can use SDL_LockTexture() to get an array of raw pixels, but we're going to use | ||
72 | SDL_LockTextureToSurface() here, because it wraps that array in a temporary SDL_Surface, | ||
73 | letting us use the surface drawing functions instead of lighting up individual pixels. */ | ||
74 | if (SDL_LockTextureToSurface(texture, NULL, &surface)) { | ||
75 | SDL_Rect r; | ||
76 | SDL_FillSurfaceRect(surface, NULL, SDL_MapRGB(SDL_GetPixelFormatDetails(surface->format), NULL, 0, 0, 0)); /* make the whole surface black */ | ||
77 | r.w = TEXTURE_SIZE; | ||
78 | r.h = TEXTURE_SIZE / 10; | ||
79 | r.x = 0; | ||
80 | r.y = (int) (((float) (TEXTURE_SIZE - r.h)) * ((scale + 1.0f) / 2.0f)); | ||
81 | SDL_FillSurfaceRect(surface, &r, SDL_MapRGB(SDL_GetPixelFormatDetails(surface->format), NULL, 0, 255, 0)); /* make a strip of the surface green */ | ||
82 | SDL_UnlockTexture(texture); /* upload the changes (and frees the temporary surface)! */ | ||
83 | } | ||
84 | |||
85 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
86 | SDL_SetRenderDrawColor(renderer, 66, 66, 66, SDL_ALPHA_OPAQUE); /* grey, full alpha */ | ||
87 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
88 | |||
89 | /* Just draw the static texture a few times. You can think of it like a | ||
90 | stamp, there isn't a limit to the number of times you can draw with it. */ | ||
91 | |||
92 | /* Center this one. It'll draw the latest version of the texture we drew while it was locked. */ | ||
93 | dst_rect.x = ((float) (WINDOW_WIDTH - TEXTURE_SIZE)) / 2.0f; | ||
94 | dst_rect.y = ((float) (WINDOW_HEIGHT - TEXTURE_SIZE)) / 2.0f; | ||
95 | dst_rect.w = dst_rect.h = (float) TEXTURE_SIZE; | ||
96 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
97 | |||
98 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
99 | |||
100 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
101 | } | ||
102 | |||
103 | /* This function runs once at shutdown. */ | ||
104 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
105 | { | ||
106 | SDL_DestroyTexture(texture); | ||
107 | /* SDL will clean up the window/renderer for us. */ | ||
108 | } | ||
109 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/thumbnail.png new file mode 100644 index 0000000..60c2a9f --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/07-streaming-textures/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/README.txt new file mode 100644 index 0000000..4ae46bc --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/README.txt | |||
@@ -0,0 +1,3 @@ | |||
1 | This example creates an SDL window and renderer, loads a texture from a .bmp | ||
2 | file, and then draws it, rotating around the center of the screen. | ||
3 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/onmouseover.webp new file mode 100644 index 0000000..69735ce --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/rotating-textures.c b/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/rotating-textures.c new file mode 100644 index 0000000..bf318ef --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/rotating-textures.c | |||
@@ -0,0 +1,113 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some | ||
3 | * rotated textures to it every frame. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | static SDL_Texture *texture = NULL; | ||
16 | static int texture_width = 0; | ||
17 | static int texture_height = 0; | ||
18 | |||
19 | #define WINDOW_WIDTH 640 | ||
20 | #define WINDOW_HEIGHT 480 | ||
21 | |||
22 | /* This function runs once at startup. */ | ||
23 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
24 | { | ||
25 | SDL_Surface *surface = NULL; | ||
26 | char *bmp_path = NULL; | ||
27 | |||
28 | SDL_SetAppMetadata("Example Renderer Rotating Textures", "1.0", "com.example.renderer-rotating-textures"); | ||
29 | |||
30 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
31 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
32 | return SDL_APP_FAILURE; | ||
33 | } | ||
34 | |||
35 | if (!SDL_CreateWindowAndRenderer("examples/renderer/rotating-textures", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
36 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
37 | return SDL_APP_FAILURE; | ||
38 | } | ||
39 | |||
40 | /* Textures are pixel data that we upload to the video hardware for fast drawing. Lots of 2D | ||
41 | engines refer to these as "sprites." We'll do a static texture (upload once, draw many | ||
42 | times) with data from a bitmap file. */ | ||
43 | |||
44 | /* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access. | ||
45 | Load a .bmp into a surface, move it to a texture from there. */ | ||
46 | SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */ | ||
47 | surface = SDL_LoadBMP(bmp_path); | ||
48 | if (!surface) { | ||
49 | SDL_Log("Couldn't load bitmap: %s", SDL_GetError()); | ||
50 | return SDL_APP_FAILURE; | ||
51 | } | ||
52 | |||
53 | SDL_free(bmp_path); /* done with this, the file is loaded. */ | ||
54 | |||
55 | texture_width = surface->w; | ||
56 | texture_height = surface->h; | ||
57 | |||
58 | texture = SDL_CreateTextureFromSurface(renderer, surface); | ||
59 | if (!texture) { | ||
60 | SDL_Log("Couldn't create static texture: %s", SDL_GetError()); | ||
61 | return SDL_APP_FAILURE; | ||
62 | } | ||
63 | |||
64 | SDL_DestroySurface(surface); /* done with this, the texture has a copy of the pixels now. */ | ||
65 | |||
66 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
67 | } | ||
68 | |||
69 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
70 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
71 | { | ||
72 | if (event->type == SDL_EVENT_QUIT) { | ||
73 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
74 | } | ||
75 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
76 | } | ||
77 | |||
78 | /* This function runs once per frame, and is the heart of the program. */ | ||
79 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
80 | { | ||
81 | SDL_FPoint center; | ||
82 | SDL_FRect dst_rect; | ||
83 | const Uint64 now = SDL_GetTicks(); | ||
84 | |||
85 | /* we'll have a texture rotate around over 2 seconds (2000 milliseconds). 360 degrees in a circle! */ | ||
86 | const float rotation = (((float) ((int) (now % 2000))) / 2000.0f) * 360.0f; | ||
87 | |||
88 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
89 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ | ||
90 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
91 | |||
92 | /* Center this one, and draw it with some rotation so it spins! */ | ||
93 | dst_rect.x = ((float) (WINDOW_WIDTH - texture_width)) / 2.0f; | ||
94 | dst_rect.y = ((float) (WINDOW_HEIGHT - texture_height)) / 2.0f; | ||
95 | dst_rect.w = (float) texture_width; | ||
96 | dst_rect.h = (float) texture_height; | ||
97 | /* rotate it around the center of the texture; you can rotate it from a different point, too! */ | ||
98 | center.x = texture_width / 2.0f; | ||
99 | center.y = texture_height / 2.0f; | ||
100 | SDL_RenderTextureRotated(renderer, texture, NULL, &dst_rect, rotation, ¢er, SDL_FLIP_NONE); | ||
101 | |||
102 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
103 | |||
104 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
105 | } | ||
106 | |||
107 | /* This function runs once at shutdown. */ | ||
108 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
109 | { | ||
110 | SDL_DestroyTexture(texture); | ||
111 | /* SDL will clean up the window/renderer for us. */ | ||
112 | } | ||
113 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/thumbnail.png new file mode 100644 index 0000000..12c51e1 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/08-rotating-textures/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/README.txt new file mode 100644 index 0000000..e13a6ec --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/README.txt | |||
@@ -0,0 +1,3 @@ | |||
1 | This example creates an SDL window and renderer, loads a texture from a .bmp | ||
2 | file, and then draws it, scaling it up and down. | ||
3 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/onmouseover.webp new file mode 100644 index 0000000..bcc967c --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/scaling-textures.c b/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/scaling-textures.c new file mode 100644 index 0000000..66060ed --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/scaling-textures.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some | ||
3 | * textures to it every frame. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | static SDL_Texture *texture = NULL; | ||
16 | static int texture_width = 0; | ||
17 | static int texture_height = 0; | ||
18 | |||
19 | #define WINDOW_WIDTH 640 | ||
20 | #define WINDOW_HEIGHT 480 | ||
21 | |||
22 | /* This function runs once at startup. */ | ||
23 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
24 | { | ||
25 | SDL_Surface *surface = NULL; | ||
26 | char *bmp_path = NULL; | ||
27 | |||
28 | SDL_SetAppMetadata("Example Renderer Scaling Textures", "1.0", "com.example.renderer-scaling-textures"); | ||
29 | |||
30 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
31 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
32 | return SDL_APP_FAILURE; | ||
33 | } | ||
34 | |||
35 | if (!SDL_CreateWindowAndRenderer("examples/renderer/scaling-textures", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
36 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
37 | return SDL_APP_FAILURE; | ||
38 | } | ||
39 | |||
40 | /* Textures are pixel data that we upload to the video hardware for fast drawing. Lots of 2D | ||
41 | engines refer to these as "sprites." We'll do a static texture (upload once, draw many | ||
42 | times) with data from a bitmap file. */ | ||
43 | |||
44 | /* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access. | ||
45 | Load a .bmp into a surface, move it to a texture from there. */ | ||
46 | SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */ | ||
47 | surface = SDL_LoadBMP(bmp_path); | ||
48 | if (!surface) { | ||
49 | SDL_Log("Couldn't load bitmap: %s", SDL_GetError()); | ||
50 | return SDL_APP_FAILURE; | ||
51 | } | ||
52 | |||
53 | SDL_free(bmp_path); /* done with this, the file is loaded. */ | ||
54 | |||
55 | texture_width = surface->w; | ||
56 | texture_height = surface->h; | ||
57 | |||
58 | texture = SDL_CreateTextureFromSurface(renderer, surface); | ||
59 | if (!texture) { | ||
60 | SDL_Log("Couldn't create static texture: %s", SDL_GetError()); | ||
61 | return SDL_APP_FAILURE; | ||
62 | } | ||
63 | |||
64 | SDL_DestroySurface(surface); /* done with this, the texture has a copy of the pixels now. */ | ||
65 | |||
66 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
67 | } | ||
68 | |||
69 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
70 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
71 | { | ||
72 | if (event->type == SDL_EVENT_QUIT) { | ||
73 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
74 | } | ||
75 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
76 | } | ||
77 | |||
78 | /* This function runs once per frame, and is the heart of the program. */ | ||
79 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
80 | { | ||
81 | SDL_FRect dst_rect; | ||
82 | const Uint64 now = SDL_GetTicks(); | ||
83 | |||
84 | /* we'll have the texture grow and shrink over a few seconds. */ | ||
85 | const float direction = ((now % 2000) >= 1000) ? 1.0f : -1.0f; | ||
86 | const float scale = ((float) (((int) (now % 1000)) - 500) / 500.0f) * direction; | ||
87 | |||
88 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
89 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ | ||
90 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
91 | |||
92 | /* center this one and make it grow and shrink. */ | ||
93 | dst_rect.w = (float) texture_width + (texture_width * scale); | ||
94 | dst_rect.h = (float) texture_height + (texture_height * scale); | ||
95 | dst_rect.x = (WINDOW_WIDTH - dst_rect.w) / 2.0f; | ||
96 | dst_rect.y = (WINDOW_HEIGHT - dst_rect.h) / 2.0f; | ||
97 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
98 | |||
99 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
100 | |||
101 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
102 | } | ||
103 | |||
104 | /* This function runs once at shutdown. */ | ||
105 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
106 | { | ||
107 | SDL_DestroyTexture(texture); | ||
108 | /* SDL will clean up the window/renderer for us. */ | ||
109 | } | ||
110 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/thumbnail.png new file mode 100644 index 0000000..c0a24c2 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/09-scaling-textures/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/README.txt new file mode 100644 index 0000000..d76d0cc --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/README.txt | |||
@@ -0,0 +1,3 @@ | |||
1 | This example creates an SDL window and renderer, loads a texture from a .bmp | ||
2 | file, and then draws geometry (arbitrary polygons) using it. | ||
3 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/geometry.c b/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/geometry.c new file mode 100644 index 0000000..77ff863 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/geometry.c | |||
@@ -0,0 +1,166 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some | ||
3 | * geometry (arbitrary polygons) to it every frame. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | static SDL_Texture *texture = NULL; | ||
16 | static int texture_width = 0; | ||
17 | static int texture_height = 0; | ||
18 | |||
19 | #define WINDOW_WIDTH 640 | ||
20 | #define WINDOW_HEIGHT 480 | ||
21 | |||
22 | /* This function runs once at startup. */ | ||
23 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
24 | { | ||
25 | SDL_Surface *surface = NULL; | ||
26 | char *bmp_path = NULL; | ||
27 | |||
28 | SDL_SetAppMetadata("Example Renderer Geometry", "1.0", "com.example.renderer-geometry"); | ||
29 | |||
30 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
31 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
32 | return SDL_APP_FAILURE; | ||
33 | } | ||
34 | |||
35 | if (!SDL_CreateWindowAndRenderer("examples/renderer/geometry", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
36 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
37 | return SDL_APP_FAILURE; | ||
38 | } | ||
39 | |||
40 | /* Textures are pixel data that we upload to the video hardware for fast drawing. Lots of 2D | ||
41 | engines refer to these as "sprites." We'll do a static texture (upload once, draw many | ||
42 | times) with data from a bitmap file. */ | ||
43 | |||
44 | /* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access. | ||
45 | Load a .bmp into a surface, move it to a texture from there. */ | ||
46 | SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */ | ||
47 | surface = SDL_LoadBMP(bmp_path); | ||
48 | if (!surface) { | ||
49 | SDL_Log("Couldn't load bitmap: %s", SDL_GetError()); | ||
50 | return SDL_APP_FAILURE; | ||
51 | } | ||
52 | |||
53 | SDL_free(bmp_path); /* done with this, the file is loaded. */ | ||
54 | |||
55 | texture_width = surface->w; | ||
56 | texture_height = surface->h; | ||
57 | |||
58 | texture = SDL_CreateTextureFromSurface(renderer, surface); | ||
59 | if (!texture) { | ||
60 | SDL_Log("Couldn't create static texture: %s", SDL_GetError()); | ||
61 | return SDL_APP_FAILURE; | ||
62 | } | ||
63 | |||
64 | SDL_DestroySurface(surface); /* done with this, the texture has a copy of the pixels now. */ | ||
65 | |||
66 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
67 | } | ||
68 | |||
69 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
70 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
71 | { | ||
72 | if (event->type == SDL_EVENT_QUIT) { | ||
73 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
74 | } | ||
75 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
76 | } | ||
77 | |||
78 | /* This function runs once per frame, and is the heart of the program. */ | ||
79 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
80 | { | ||
81 | const Uint64 now = SDL_GetTicks(); | ||
82 | |||
83 | /* we'll have the triangle grow and shrink over a few seconds. */ | ||
84 | const float direction = ((now % 2000) >= 1000) ? 1.0f : -1.0f; | ||
85 | const float scale = ((float) (((int) (now % 1000)) - 500) / 500.0f) * direction; | ||
86 | const float size = 200.0f + (200.0f * scale); | ||
87 | |||
88 | SDL_Vertex vertices[4]; | ||
89 | int i; | ||
90 | |||
91 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
92 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ | ||
93 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
94 | |||
95 | /* Draw a single triangle with a different color at each vertex. Center this one and make it grow and shrink. */ | ||
96 | /* You always draw triangles with this, but you can string triangles together to form polygons. */ | ||
97 | SDL_zeroa(vertices); | ||
98 | vertices[0].position.x = ((float) WINDOW_WIDTH) / 2.0f; | ||
99 | vertices[0].position.y = (((float) WINDOW_HEIGHT) - size) / 2.0f; | ||
100 | vertices[0].color.r = 1.0f; | ||
101 | vertices[0].color.a = 1.0f; | ||
102 | vertices[1].position.x = (((float) WINDOW_WIDTH) + size) / 2.0f; | ||
103 | vertices[1].position.y = (((float) WINDOW_HEIGHT) + size) / 2.0f; | ||
104 | vertices[1].color.g = 1.0f; | ||
105 | vertices[1].color.a = 1.0f; | ||
106 | vertices[2].position.x = (((float) WINDOW_WIDTH) - size) / 2.0f; | ||
107 | vertices[2].position.y = (((float) WINDOW_HEIGHT) + size) / 2.0f; | ||
108 | vertices[2].color.b = 1.0f; | ||
109 | vertices[2].color.a = 1.0f; | ||
110 | |||
111 | SDL_RenderGeometry(renderer, NULL, vertices, 3, NULL, 0); | ||
112 | |||
113 | /* you can also map a texture to the geometry! Texture coordinates go from 0.0f to 1.0f. That will be the location | ||
114 | in the texture bound to this vertex. */ | ||
115 | SDL_zeroa(vertices); | ||
116 | vertices[0].position.x = 10.0f; | ||
117 | vertices[0].position.y = 10.0f; | ||
118 | vertices[0].color.r = vertices[0].color.g = vertices[0].color.b = vertices[0].color.a = 1.0f; | ||
119 | vertices[0].tex_coord.x = 0.0f; | ||
120 | vertices[0].tex_coord.y = 0.0f; | ||
121 | vertices[1].position.x = 150.0f; | ||
122 | vertices[1].position.y = 10.0f; | ||
123 | vertices[1].color.r = vertices[1].color.g = vertices[1].color.b = vertices[1].color.a = 1.0f; | ||
124 | vertices[1].tex_coord.x = 1.0f; | ||
125 | vertices[1].tex_coord.y = 0.0f; | ||
126 | vertices[2].position.x = 10.0f; | ||
127 | vertices[2].position.y = 150.0f; | ||
128 | vertices[2].color.r = vertices[2].color.g = vertices[2].color.b = vertices[2].color.a = 1.0f; | ||
129 | vertices[2].tex_coord.x = 0.0f; | ||
130 | vertices[2].tex_coord.y = 1.0f; | ||
131 | SDL_RenderGeometry(renderer, texture, vertices, 3, NULL, 0); | ||
132 | |||
133 | /* Did that only draw half of the texture? You can do multiple triangles sharing some vertices, | ||
134 | using indices, to get the whole thing on the screen: */ | ||
135 | |||
136 | /* Let's just move this over so it doesn't overlap... */ | ||
137 | for (i = 0; i < 3; i++) { | ||
138 | vertices[i].position.x += 450; | ||
139 | } | ||
140 | |||
141 | /* we need one more vertex, since the two triangles can share two of them. */ | ||
142 | vertices[3].position.x = 600.0f; | ||
143 | vertices[3].position.y = 150.0f; | ||
144 | vertices[3].color.r = vertices[3].color.g = vertices[3].color.b = vertices[3].color.a = 1.0f; | ||
145 | vertices[3].tex_coord.x = 1.0f; | ||
146 | vertices[3].tex_coord.y = 1.0f; | ||
147 | |||
148 | /* And an index to tell it to reuse some of the vertices between triangles... */ | ||
149 | { | ||
150 | /* 4 vertices, but 6 actual places they used. Indices need less bandwidth to transfer and can reorder vertices easily! */ | ||
151 | const int indices[] = { 0, 1, 2, 1, 2, 3 }; | ||
152 | SDL_RenderGeometry(renderer, texture, vertices, 4, indices, SDL_arraysize(indices)); | ||
153 | } | ||
154 | |||
155 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
156 | |||
157 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
158 | } | ||
159 | |||
160 | /* This function runs once at shutdown. */ | ||
161 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
162 | { | ||
163 | SDL_DestroyTexture(texture); | ||
164 | /* SDL will clean up the window/renderer for us. */ | ||
165 | } | ||
166 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/onmouseover.webp new file mode 100644 index 0000000..37a518c --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/thumbnail.png new file mode 100644 index 0000000..89195fb --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/10-geometry/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/README.txt new file mode 100644 index 0000000..66f233b --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/README.txt | |||
@@ -0,0 +1,3 @@ | |||
1 | This example creates an SDL window and renderer, loads a texture from a | ||
2 | .bmp file, and then draws it a few times each frame, adjusting the colors. | ||
3 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/color-mods.c b/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/color-mods.c new file mode 100644 index 0000000..8877232 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/color-mods.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some | ||
3 | * textures to it every frame, adjusting their color. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | static SDL_Texture *texture = NULL; | ||
16 | static int texture_width = 0; | ||
17 | static int texture_height = 0; | ||
18 | |||
19 | #define WINDOW_WIDTH 640 | ||
20 | #define WINDOW_HEIGHT 480 | ||
21 | |||
22 | /* This function runs once at startup. */ | ||
23 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
24 | { | ||
25 | SDL_Surface *surface = NULL; | ||
26 | char *bmp_path = NULL; | ||
27 | |||
28 | SDL_SetAppMetadata("Example Renderer Color Mods", "1.0", "com.example.renderer-color-mods"); | ||
29 | |||
30 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
31 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
32 | return SDL_APP_FAILURE; | ||
33 | } | ||
34 | |||
35 | if (!SDL_CreateWindowAndRenderer("examples/renderer/color-mods", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
36 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
37 | return SDL_APP_FAILURE; | ||
38 | } | ||
39 | |||
40 | /* Textures are pixel data that we upload to the video hardware for fast drawing. Lots of 2D | ||
41 | engines refer to these as "sprites." We'll do a static texture (upload once, draw many | ||
42 | times) with data from a bitmap file. */ | ||
43 | |||
44 | /* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access. | ||
45 | Load a .bmp into a surface, move it to a texture from there. */ | ||
46 | SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */ | ||
47 | surface = SDL_LoadBMP(bmp_path); | ||
48 | if (!surface) { | ||
49 | SDL_Log("Couldn't load bitmap: %s", SDL_GetError()); | ||
50 | return SDL_APP_FAILURE; | ||
51 | } | ||
52 | |||
53 | SDL_free(bmp_path); /* done with this, the file is loaded. */ | ||
54 | |||
55 | texture_width = surface->w; | ||
56 | texture_height = surface->h; | ||
57 | |||
58 | texture = SDL_CreateTextureFromSurface(renderer, surface); | ||
59 | if (!texture) { | ||
60 | SDL_Log("Couldn't create static texture: %s", SDL_GetError()); | ||
61 | return SDL_APP_FAILURE; | ||
62 | } | ||
63 | |||
64 | SDL_DestroySurface(surface); /* done with this, the texture has a copy of the pixels now. */ | ||
65 | |||
66 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
67 | } | ||
68 | |||
69 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
70 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
71 | { | ||
72 | if (event->type == SDL_EVENT_QUIT) { | ||
73 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
74 | } | ||
75 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
76 | } | ||
77 | |||
78 | /* This function runs once per frame, and is the heart of the program. */ | ||
79 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
80 | { | ||
81 | SDL_FRect dst_rect; | ||
82 | const double now = ((double)SDL_GetTicks()) / 1000.0; /* convert from milliseconds to seconds. */ | ||
83 | /* choose the modulation values for the center texture. The sine wave trick makes it fade between colors smoothly. */ | ||
84 | const float red = (float) (0.5 + 0.5 * SDL_sin(now)); | ||
85 | const float green = (float) (0.5 + 0.5 * SDL_sin(now + SDL_PI_D * 2 / 3)); | ||
86 | const float blue = (float) (0.5 + 0.5 * SDL_sin(now + SDL_PI_D * 4 / 3)); | ||
87 | |||
88 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
89 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ | ||
90 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
91 | |||
92 | /* Just draw the static texture a few times. You can think of it like a | ||
93 | stamp, there isn't a limit to the number of times you can draw with it. */ | ||
94 | |||
95 | /* Color modulation multiplies each pixel's red, green, and blue intensities by the mod values, | ||
96 | so multiplying by 1.0f will leave a color intensity alone, 0.0f will shut off that color | ||
97 | completely, etc. */ | ||
98 | |||
99 | /* top left; let's make this one blue! */ | ||
100 | dst_rect.x = 0.0f; | ||
101 | dst_rect.y = 0.0f; | ||
102 | dst_rect.w = (float) texture_width; | ||
103 | dst_rect.h = (float) texture_height; | ||
104 | SDL_SetTextureColorModFloat(texture, 0.0f, 0.0f, 1.0f); /* kill all red and green. */ | ||
105 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
106 | |||
107 | /* center this one, and have it cycle through red/green/blue modulations. */ | ||
108 | dst_rect.x = ((float) (WINDOW_WIDTH - texture_width)) / 2.0f; | ||
109 | dst_rect.y = ((float) (WINDOW_HEIGHT - texture_height)) / 2.0f; | ||
110 | dst_rect.w = (float) texture_width; | ||
111 | dst_rect.h = (float) texture_height; | ||
112 | SDL_SetTextureColorModFloat(texture, red, green, blue); | ||
113 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
114 | |||
115 | /* bottom right; let's make this one red! */ | ||
116 | dst_rect.x = (float) (WINDOW_WIDTH - texture_width); | ||
117 | dst_rect.y = (float) (WINDOW_HEIGHT - texture_height); | ||
118 | dst_rect.w = (float) texture_width; | ||
119 | dst_rect.h = (float) texture_height; | ||
120 | SDL_SetTextureColorModFloat(texture, 1.0f, 0.0f, 0.0f); /* kill all green and blue. */ | ||
121 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
122 | |||
123 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
124 | |||
125 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
126 | } | ||
127 | |||
128 | /* This function runs once at shutdown. */ | ||
129 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
130 | { | ||
131 | SDL_DestroyTexture(texture); | ||
132 | /* SDL will clean up the window/renderer for us. */ | ||
133 | } | ||
134 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/onmouseover.webp new file mode 100644 index 0000000..2157063 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/thumbnail.png new file mode 100644 index 0000000..d471112 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/11-color-mods/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/14-viewport/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/14-viewport/README.txt new file mode 100644 index 0000000..9da7c7a --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/14-viewport/README.txt | |||
@@ -0,0 +1,4 @@ | |||
1 | This example creates an SDL window and renderer, loads a texture | ||
2 | from a .bmp file, and then draws it a few times each frame, adjusting | ||
3 | the viewport before each draw. | ||
4 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/14-viewport/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/14-viewport/thumbnail.png new file mode 100644 index 0000000..bad5521 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/14-viewport/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/14-viewport/viewport.c b/src/contrib/SDL-3.2.20/examples/renderer/14-viewport/viewport.c new file mode 100644 index 0000000..0a6c015 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/14-viewport/viewport.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some | ||
3 | * textures to it every frame, adjusting the viewport. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | static SDL_Texture *texture = NULL; | ||
16 | static int texture_width = 0; | ||
17 | static int texture_height = 0; | ||
18 | |||
19 | #define WINDOW_WIDTH 640 | ||
20 | #define WINDOW_HEIGHT 480 | ||
21 | |||
22 | /* This function runs once at startup. */ | ||
23 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
24 | { | ||
25 | SDL_Surface *surface = NULL; | ||
26 | char *bmp_path = NULL; | ||
27 | |||
28 | SDL_SetAppMetadata("Example Renderer Viewport", "1.0", "com.example.renderer-viewport"); | ||
29 | |||
30 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
31 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
32 | return SDL_APP_FAILURE; | ||
33 | } | ||
34 | |||
35 | if (!SDL_CreateWindowAndRenderer("examples/renderer/viewport", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
36 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
37 | return SDL_APP_FAILURE; | ||
38 | } | ||
39 | |||
40 | /* Textures are pixel data that we upload to the video hardware for fast drawing. Lots of 2D | ||
41 | engines refer to these as "sprites." We'll do a static texture (upload once, draw many | ||
42 | times) with data from a bitmap file. */ | ||
43 | |||
44 | /* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access. | ||
45 | Load a .bmp into a surface, move it to a texture from there. */ | ||
46 | SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */ | ||
47 | surface = SDL_LoadBMP(bmp_path); | ||
48 | if (!surface) { | ||
49 | SDL_Log("Couldn't load bitmap: %s", SDL_GetError()); | ||
50 | return SDL_APP_FAILURE; | ||
51 | } | ||
52 | |||
53 | SDL_free(bmp_path); /* done with this, the file is loaded. */ | ||
54 | |||
55 | texture_width = surface->w; | ||
56 | texture_height = surface->h; | ||
57 | |||
58 | texture = SDL_CreateTextureFromSurface(renderer, surface); | ||
59 | if (!texture) { | ||
60 | SDL_Log("Couldn't create static texture: %s", SDL_GetError()); | ||
61 | return SDL_APP_FAILURE; | ||
62 | } | ||
63 | |||
64 | SDL_DestroySurface(surface); /* done with this, the texture has a copy of the pixels now. */ | ||
65 | |||
66 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
67 | } | ||
68 | |||
69 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
70 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
71 | { | ||
72 | if (event->type == SDL_EVENT_QUIT) { | ||
73 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
74 | } | ||
75 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
76 | } | ||
77 | |||
78 | /* This function runs once per frame, and is the heart of the program. */ | ||
79 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
80 | { | ||
81 | SDL_FRect dst_rect = { 0, 0, (float) texture_width, (float) texture_height }; | ||
82 | SDL_Rect viewport; | ||
83 | |||
84 | /* Setting a viewport has the effect of limiting the area that rendering | ||
85 | can happen, and making coordinate (0, 0) live somewhere else in the | ||
86 | window. It does _not_ scale rendering to fit the viewport. */ | ||
87 | |||
88 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
89 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ | ||
90 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
91 | |||
92 | /* Draw once with the whole window as the viewport. */ | ||
93 | viewport.x = 0; | ||
94 | viewport.y = 0; | ||
95 | viewport.w = WINDOW_WIDTH / 2; | ||
96 | viewport.h = WINDOW_HEIGHT / 2; | ||
97 | SDL_SetRenderViewport(renderer, NULL); /* NULL means "use the whole window" */ | ||
98 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
99 | |||
100 | /* top right quarter of the window. */ | ||
101 | viewport.x = WINDOW_WIDTH / 2; | ||
102 | viewport.y = WINDOW_HEIGHT / 2; | ||
103 | viewport.w = WINDOW_WIDTH / 2; | ||
104 | viewport.h = WINDOW_HEIGHT / 2; | ||
105 | SDL_SetRenderViewport(renderer, &viewport); | ||
106 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
107 | |||
108 | /* bottom 20% of the window. Note it clips the width! */ | ||
109 | viewport.x = 0; | ||
110 | viewport.y = WINDOW_HEIGHT - (WINDOW_HEIGHT / 5); | ||
111 | viewport.w = WINDOW_WIDTH / 5; | ||
112 | viewport.h = WINDOW_HEIGHT / 5; | ||
113 | SDL_SetRenderViewport(renderer, &viewport); | ||
114 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
115 | |||
116 | /* what happens if you try to draw above the viewport? It should clip! */ | ||
117 | viewport.x = 100; | ||
118 | viewport.y = 200; | ||
119 | viewport.w = WINDOW_WIDTH; | ||
120 | viewport.h = WINDOW_HEIGHT; | ||
121 | SDL_SetRenderViewport(renderer, &viewport); | ||
122 | dst_rect.y = -50; | ||
123 | SDL_RenderTexture(renderer, texture, NULL, &dst_rect); | ||
124 | |||
125 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
126 | |||
127 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
128 | } | ||
129 | |||
130 | /* This function runs once at shutdown. */ | ||
131 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
132 | { | ||
133 | SDL_DestroyTexture(texture); | ||
134 | /* SDL will clean up the window/renderer for us. */ | ||
135 | } | ||
136 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/README.txt new file mode 100644 index 0000000..48c9f1f --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/README.txt | |||
@@ -0,0 +1,5 @@ | |||
1 | This example creates an SDL window and renderer, loads a texture | ||
2 | from a .bmp file, and stretches it across the window. Each frame, we move | ||
3 | the clipping rectangle around, so only a small square of the texture is | ||
4 | actually drawn. | ||
5 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/cliprect.c b/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/cliprect.c new file mode 100644 index 0000000..058072c --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/cliprect.c | |||
@@ -0,0 +1,137 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws a scene | ||
3 | * to it every frame, while sliding around a clipping rectangle. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | #define WINDOW_WIDTH 640 | ||
13 | #define WINDOW_HEIGHT 480 | ||
14 | #define CLIPRECT_SIZE 250 | ||
15 | #define CLIPRECT_SPEED 200 /* pixels per second */ | ||
16 | |||
17 | /* We will use this renderer to draw into this window every frame. */ | ||
18 | static SDL_Window *window = NULL; | ||
19 | static SDL_Renderer *renderer = NULL; | ||
20 | static SDL_Texture *texture = NULL; | ||
21 | static SDL_FPoint cliprect_position; | ||
22 | static SDL_FPoint cliprect_direction; | ||
23 | static Uint64 last_time = 0; | ||
24 | |||
25 | /* A lot of this program is examples/renderer/02-primitives, so we have a good | ||
26 | visual that we can slide a clip rect around. The actual new magic in here | ||
27 | is the SDL_SetRenderClipRect() function. */ | ||
28 | |||
29 | /* This function runs once at startup. */ | ||
30 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
31 | { | ||
32 | SDL_Surface *surface = NULL; | ||
33 | char *bmp_path = NULL; | ||
34 | |||
35 | SDL_SetAppMetadata("Example Renderer Clipping Rectangle", "1.0", "com.example.renderer-cliprect"); | ||
36 | |||
37 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
38 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
39 | return SDL_APP_FAILURE; | ||
40 | } | ||
41 | |||
42 | if (!SDL_CreateWindowAndRenderer("examples/renderer/cliprect", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
43 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
44 | return SDL_APP_FAILURE; | ||
45 | } | ||
46 | |||
47 | cliprect_direction.x = cliprect_direction.y = 1.0f; | ||
48 | |||
49 | last_time = SDL_GetTicks(); | ||
50 | |||
51 | /* Textures are pixel data that we upload to the video hardware for fast drawing. Lots of 2D | ||
52 | engines refer to these as "sprites." We'll do a static texture (upload once, draw many | ||
53 | times) with data from a bitmap file. */ | ||
54 | |||
55 | /* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access. | ||
56 | Load a .bmp into a surface, move it to a texture from there. */ | ||
57 | SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */ | ||
58 | surface = SDL_LoadBMP(bmp_path); | ||
59 | if (!surface) { | ||
60 | SDL_Log("Couldn't load bitmap: %s", SDL_GetError()); | ||
61 | return SDL_APP_FAILURE; | ||
62 | } | ||
63 | |||
64 | SDL_free(bmp_path); /* done with this, the file is loaded. */ | ||
65 | |||
66 | texture = SDL_CreateTextureFromSurface(renderer, surface); | ||
67 | if (!texture) { | ||
68 | SDL_Log("Couldn't create static texture: %s", SDL_GetError()); | ||
69 | return SDL_APP_FAILURE; | ||
70 | } | ||
71 | |||
72 | SDL_DestroySurface(surface); /* done with this, the texture has a copy of the pixels now. */ | ||
73 | |||
74 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
75 | } | ||
76 | |||
77 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
78 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
79 | { | ||
80 | if (event->type == SDL_EVENT_QUIT) { | ||
81 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
82 | } | ||
83 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
84 | } | ||
85 | |||
86 | /* This function runs once per frame, and is the heart of the program. */ | ||
87 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
88 | { | ||
89 | const SDL_Rect cliprect = { (int) SDL_roundf(cliprect_position.x), (int) SDL_roundf(cliprect_position.y), CLIPRECT_SIZE, CLIPRECT_SIZE }; | ||
90 | const Uint64 now = SDL_GetTicks(); | ||
91 | const float elapsed = ((float) (now - last_time)) / 1000.0f; /* seconds since last iteration */ | ||
92 | const float distance = elapsed * CLIPRECT_SPEED; | ||
93 | |||
94 | /* Set a new clipping rectangle position */ | ||
95 | cliprect_position.x += distance * cliprect_direction.x; | ||
96 | if (cliprect_position.x < 0.0f) { | ||
97 | cliprect_position.x = 0.0f; | ||
98 | cliprect_direction.x = 1.0f; | ||
99 | } else if (cliprect_position.x >= (WINDOW_WIDTH - CLIPRECT_SIZE)) { | ||
100 | cliprect_position.x = (WINDOW_WIDTH - CLIPRECT_SIZE) - 1; | ||
101 | cliprect_direction.x = -1.0f; | ||
102 | } | ||
103 | |||
104 | cliprect_position.y += distance * cliprect_direction.y; | ||
105 | if (cliprect_position.y < 0.0f) { | ||
106 | cliprect_position.y = 0.0f; | ||
107 | cliprect_direction.y = 1.0f; | ||
108 | } else if (cliprect_position.y >= (WINDOW_HEIGHT - CLIPRECT_SIZE)) { | ||
109 | cliprect_position.y = (WINDOW_HEIGHT - CLIPRECT_SIZE) - 1; | ||
110 | cliprect_direction.y = -1.0f; | ||
111 | } | ||
112 | SDL_SetRenderClipRect(renderer, &cliprect); | ||
113 | |||
114 | last_time = now; | ||
115 | |||
116 | /* okay, now draw! */ | ||
117 | |||
118 | /* Note that SDL_RenderClear is _not_ affected by the clipping rectangle! */ | ||
119 | SDL_SetRenderDrawColor(renderer, 33, 33, 33, SDL_ALPHA_OPAQUE); /* grey, full alpha */ | ||
120 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
121 | |||
122 | /* stretch the texture across the entire window. Only the piece in the | ||
123 | clipping rectangle will actually render, though! */ | ||
124 | SDL_RenderTexture(renderer, texture, NULL, NULL); | ||
125 | |||
126 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
127 | |||
128 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
129 | } | ||
130 | |||
131 | /* This function runs once at shutdown. */ | ||
132 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
133 | { | ||
134 | SDL_DestroyTexture(texture); | ||
135 | /* SDL will clean up the window/renderer for us. */ | ||
136 | } | ||
137 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/onmouseover.webp new file mode 100644 index 0000000..943eeef --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/thumbnail.png new file mode 100644 index 0000000..127e6fa --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/15-cliprect/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/README.txt new file mode 100644 index 0000000..dd474e6 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/README.txt | |||
@@ -0,0 +1,12 @@ | |||
1 | This example creates an SDL window and renderer, and draws a | ||
2 | rotating texture to it, reads back the rendered pixels, converts them to | ||
3 | black and white, and then draws the converted image to a corner of the | ||
4 | screen. | ||
5 | |||
6 | This isn't necessarily an efficient thing to do--in real life one might | ||
7 | want to do this sort of thing with a render target--but it's just a visual | ||
8 | example of how to use SDL_RenderReadPixels(). | ||
9 | |||
10 | A better, but less visual, use of SDL_RenderReadPixels() is to make | ||
11 | screenshots: you grab the current contents of the screen, and save the pixels | ||
12 | as a bitmap file or whatever. | ||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/onmouseover.webp b/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/onmouseover.webp new file mode 100644 index 0000000..bb4e5c4 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/onmouseover.webp | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/read-pixels.c b/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/read-pixels.c new file mode 100644 index 0000000..556b490 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/read-pixels.c | |||
@@ -0,0 +1,178 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and draws a | ||
3 | * rotating texture to it, reads back the rendered pixels, converts them to | ||
4 | * black and white, and then draws the converted image to a corner of the | ||
5 | * screen. | ||
6 | * | ||
7 | * This isn't necessarily an efficient thing to do--in real life one might | ||
8 | * want to do this sort of thing with a render target--but it's just a visual | ||
9 | * example of how to use SDL_RenderReadPixels(). | ||
10 | * | ||
11 | * This code is public domain. Feel free to use it for any purpose! | ||
12 | */ | ||
13 | |||
14 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
15 | #include <SDL3/SDL.h> | ||
16 | #include <SDL3/SDL_main.h> | ||
17 | |||
18 | /* We will use this renderer to draw into this window every frame. */ | ||
19 | static SDL_Window *window = NULL; | ||
20 | static SDL_Renderer *renderer = NULL; | ||
21 | static SDL_Texture *texture = NULL; | ||
22 | static int texture_width = 0; | ||
23 | static int texture_height = 0; | ||
24 | static SDL_Texture *converted_texture = NULL; | ||
25 | static int converted_texture_width = 0; | ||
26 | static int converted_texture_height = 0; | ||
27 | |||
28 | #define WINDOW_WIDTH 640 | ||
29 | #define WINDOW_HEIGHT 480 | ||
30 | |||
31 | /* This function runs once at startup. */ | ||
32 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
33 | { | ||
34 | SDL_Surface *surface = NULL; | ||
35 | char *bmp_path = NULL; | ||
36 | |||
37 | SDL_SetAppMetadata("Example Renderer Read Pixels", "1.0", "com.example.renderer-read-pixels"); | ||
38 | |||
39 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
40 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
41 | return SDL_APP_FAILURE; | ||
42 | } | ||
43 | |||
44 | if (!SDL_CreateWindowAndRenderer("examples/renderer/read-pixels", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
45 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
46 | return SDL_APP_FAILURE; | ||
47 | } | ||
48 | |||
49 | /* Textures are pixel data that we upload to the video hardware for fast drawing. Lots of 2D | ||
50 | engines refer to these as "sprites." We'll do a static texture (upload once, draw many | ||
51 | times) with data from a bitmap file. */ | ||
52 | |||
53 | /* SDL_Surface is pixel data the CPU can access. SDL_Texture is pixel data the GPU can access. | ||
54 | Load a .bmp into a surface, move it to a texture from there. */ | ||
55 | SDL_asprintf(&bmp_path, "%ssample.bmp", SDL_GetBasePath()); /* allocate a string of the full file path */ | ||
56 | surface = SDL_LoadBMP(bmp_path); | ||
57 | if (!surface) { | ||
58 | SDL_Log("Couldn't load bitmap: %s", SDL_GetError()); | ||
59 | return SDL_APP_FAILURE; | ||
60 | } | ||
61 | |||
62 | SDL_free(bmp_path); /* done with this, the file is loaded. */ | ||
63 | |||
64 | texture_width = surface->w; | ||
65 | texture_height = surface->h; | ||
66 | |||
67 | texture = SDL_CreateTextureFromSurface(renderer, surface); | ||
68 | if (!texture) { | ||
69 | SDL_Log("Couldn't create static texture: %s", SDL_GetError()); | ||
70 | return SDL_APP_FAILURE; | ||
71 | } | ||
72 | |||
73 | SDL_DestroySurface(surface); /* done with this, the texture has a copy of the pixels now. */ | ||
74 | |||
75 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
76 | } | ||
77 | |||
78 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
79 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
80 | { | ||
81 | if (event->type == SDL_EVENT_QUIT) { | ||
82 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
83 | } | ||
84 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
85 | } | ||
86 | |||
87 | /* This function runs once per frame, and is the heart of the program. */ | ||
88 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
89 | { | ||
90 | const Uint64 now = SDL_GetTicks(); | ||
91 | SDL_Surface *surface; | ||
92 | SDL_FPoint center; | ||
93 | SDL_FRect dst_rect; | ||
94 | |||
95 | /* we'll have a texture rotate around over 2 seconds (2000 milliseconds). 360 degrees in a circle! */ | ||
96 | const float rotation = (((float) ((int) (now % 2000))) / 2000.0f) * 360.0f; | ||
97 | |||
98 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
99 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ | ||
100 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
101 | |||
102 | /* Center this one, and draw it with some rotation so it spins! */ | ||
103 | dst_rect.x = ((float) (WINDOW_WIDTH - texture_width)) / 2.0f; | ||
104 | dst_rect.y = ((float) (WINDOW_HEIGHT - texture_height)) / 2.0f; | ||
105 | dst_rect.w = (float) texture_width; | ||
106 | dst_rect.h = (float) texture_height; | ||
107 | /* rotate it around the center of the texture; you can rotate it from a different point, too! */ | ||
108 | center.x = texture_width / 2.0f; | ||
109 | center.y = texture_height / 2.0f; | ||
110 | SDL_RenderTextureRotated(renderer, texture, NULL, &dst_rect, rotation, ¢er, SDL_FLIP_NONE); | ||
111 | |||
112 | /* this next whole thing is _super_ expensive. Seriously, don't do this in real life. */ | ||
113 | |||
114 | /* Download the pixels of what has just been rendered. This has to wait for the GPU to finish rendering it and everything before it, | ||
115 | and then make an expensive copy from the GPU to system RAM! */ | ||
116 | surface = SDL_RenderReadPixels(renderer, NULL); | ||
117 | |||
118 | /* This is also expensive, but easier: convert the pixels to a format we want. */ | ||
119 | if (surface && (surface->format != SDL_PIXELFORMAT_RGBA8888) && (surface->format != SDL_PIXELFORMAT_BGRA8888)) { | ||
120 | SDL_Surface *converted = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA8888); | ||
121 | SDL_DestroySurface(surface); | ||
122 | surface = converted; | ||
123 | } | ||
124 | |||
125 | if (surface) { | ||
126 | /* Rebuild converted_texture if the dimensions have changed (window resized, etc). */ | ||
127 | if ((surface->w != converted_texture_width) || (surface->h != converted_texture_height)) { | ||
128 | SDL_DestroyTexture(converted_texture); | ||
129 | converted_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, surface->w, surface->h); | ||
130 | if (!converted_texture) { | ||
131 | SDL_Log("Couldn't (re)create conversion texture: %s", SDL_GetError()); | ||
132 | return SDL_APP_FAILURE; | ||
133 | } | ||
134 | converted_texture_width = surface->w; | ||
135 | converted_texture_height = surface->h; | ||
136 | } | ||
137 | |||
138 | /* Turn each pixel into either black or white. This is a lousy technique but it works here. | ||
139 | In real life, something like Floyd-Steinberg dithering might work | ||
140 | better: https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering*/ | ||
141 | int x, y; | ||
142 | for (y = 0; y < surface->h; y++) { | ||
143 | Uint32 *pixels = (Uint32 *) (((Uint8 *) surface->pixels) + (y * surface->pitch)); | ||
144 | for (x = 0; x < surface->w; x++) { | ||
145 | Uint8 *p = (Uint8 *) (&pixels[x]); | ||
146 | const Uint32 average = (((Uint32) p[1]) + ((Uint32) p[2]) + ((Uint32) p[3])) / 3; | ||
147 | if (average == 0) { | ||
148 | p[0] = p[3] = 0xFF; p[1] = p[2] = 0; /* make pure black pixels red. */ | ||
149 | } else { | ||
150 | p[1] = p[2] = p[3] = (average > 50) ? 0xFF : 0x00; /* make everything else either black or white. */ | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | |||
155 | /* upload the processed pixels back into a texture. */ | ||
156 | SDL_UpdateTexture(converted_texture, NULL, surface->pixels, surface->pitch); | ||
157 | SDL_DestroySurface(surface); | ||
158 | |||
159 | /* draw the texture to the top-left of the screen. */ | ||
160 | dst_rect.x = dst_rect.y = 0.0f; | ||
161 | dst_rect.w = ((float) WINDOW_WIDTH) / 4.0f; | ||
162 | dst_rect.h = ((float) WINDOW_HEIGHT) / 4.0f; | ||
163 | SDL_RenderTexture(renderer, converted_texture, NULL, &dst_rect); | ||
164 | } | ||
165 | |||
166 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
167 | |||
168 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
169 | } | ||
170 | |||
171 | /* This function runs once at shutdown. */ | ||
172 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
173 | { | ||
174 | SDL_DestroyTexture(converted_texture); | ||
175 | SDL_DestroyTexture(texture); | ||
176 | /* SDL will clean up the window/renderer for us. */ | ||
177 | } | ||
178 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/thumbnail.png new file mode 100644 index 0000000..8da02ac --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/17-read-pixels/thumbnail.png | |||
Binary files differ | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/README.txt b/src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/README.txt new file mode 100644 index 0000000..0f0c868 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/README.txt | |||
@@ -0,0 +1,4 @@ | |||
1 | This example creates an SDL window and renderer, and draws some text | ||
2 | using SDL_RenderDebugText(). This is not quality text rendering, but it can | ||
3 | be helpful for simple apps, debugging, or showing something in a pinch. | ||
4 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/debug-text.c b/src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/debug-text.c new file mode 100644 index 0000000..62005e6 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/debug-text.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * This example creates an SDL window and renderer, and then draws some text | ||
3 | * using SDL_RenderDebugText() every frame. | ||
4 | * | ||
5 | * This code is public domain. Feel free to use it for any purpose! | ||
6 | */ | ||
7 | |||
8 | #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ | ||
9 | #include <SDL3/SDL.h> | ||
10 | #include <SDL3/SDL_main.h> | ||
11 | |||
12 | /* We will use this renderer to draw into this window every frame. */ | ||
13 | static SDL_Window *window = NULL; | ||
14 | static SDL_Renderer *renderer = NULL; | ||
15 | |||
16 | #define WINDOW_WIDTH 640 | ||
17 | #define WINDOW_HEIGHT 480 | ||
18 | |||
19 | /* This function runs once at startup. */ | ||
20 | SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) | ||
21 | { | ||
22 | SDL_SetAppMetadata("Example Renderer Debug Texture", "1.0", "com.example.renderer-debug-text"); | ||
23 | |||
24 | if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
25 | SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); | ||
26 | return SDL_APP_FAILURE; | ||
27 | } | ||
28 | |||
29 | if (!SDL_CreateWindowAndRenderer("examples/renderer/debug-text", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { | ||
30 | SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); | ||
31 | return SDL_APP_FAILURE; | ||
32 | } | ||
33 | |||
34 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
35 | } | ||
36 | |||
37 | /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ | ||
38 | SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) | ||
39 | { | ||
40 | if (event->type == SDL_EVENT_QUIT) { | ||
41 | return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ | ||
42 | } | ||
43 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
44 | } | ||
45 | |||
46 | /* This function runs once per frame, and is the heart of the program. */ | ||
47 | SDL_AppResult SDL_AppIterate(void *appstate) | ||
48 | { | ||
49 | const int charsize = SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE; | ||
50 | |||
51 | /* as you can see from this, rendering draws over whatever was drawn before it. */ | ||
52 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ | ||
53 | SDL_RenderClear(renderer); /* start with a blank canvas. */ | ||
54 | |||
55 | SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); /* white, full alpha */ | ||
56 | SDL_RenderDebugText(renderer, 272, 100, "Hello world!"); | ||
57 | SDL_RenderDebugText(renderer, 224, 150, "This is some debug text."); | ||
58 | |||
59 | SDL_SetRenderDrawColor(renderer, 51, 102, 255, SDL_ALPHA_OPAQUE); /* light blue, full alpha */ | ||
60 | SDL_RenderDebugText(renderer, 184, 200, "You can do it in different colors."); | ||
61 | SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); /* white, full alpha */ | ||
62 | |||
63 | SDL_SetRenderScale(renderer, 4.0f, 4.0f); | ||
64 | SDL_RenderDebugText(renderer, 14, 65, "It can be scaled."); | ||
65 | SDL_SetRenderScale(renderer, 1.0f, 1.0f); | ||
66 | SDL_RenderDebugText(renderer, 64, 350, "This only does ASCII chars. So this laughing emoji won't draw: 🤣"); | ||
67 | |||
68 | SDL_RenderDebugTextFormat(renderer, (float) ((WINDOW_WIDTH - (charsize * 46)) / 2), 400, "(This program has been running for %" SDL_PRIu64 " seconds.)", SDL_GetTicks() / 1000); | ||
69 | |||
70 | SDL_RenderPresent(renderer); /* put it all on the screen! */ | ||
71 | |||
72 | return SDL_APP_CONTINUE; /* carry on with the program! */ | ||
73 | } | ||
74 | |||
75 | /* This function runs once at shutdown. */ | ||
76 | void SDL_AppQuit(void *appstate, SDL_AppResult result) | ||
77 | { | ||
78 | /* SDL will clean up the window/renderer for us. */ | ||
79 | } | ||
80 | |||
diff --git a/src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/thumbnail.png b/src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/thumbnail.png new file mode 100644 index 0000000..f08e469 --- /dev/null +++ b/src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/thumbnail.png | |||
Binary files differ | |||