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/01-clear | |
parent | 8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff) |
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/examples/renderer/01-clear')
-rw-r--r-- | src/contrib/SDL-3.2.20/examples/renderer/01-clear/README.txt | 3 | ||||
-rw-r--r-- | src/contrib/SDL-3.2.20/examples/renderer/01-clear/clear.c | 68 | ||||
-rw-r--r-- | src/contrib/SDL-3.2.20/examples/renderer/01-clear/onmouseover.webp | bin | 0 -> 69392 bytes | |||
-rw-r--r-- | src/contrib/SDL-3.2.20/examples/renderer/01-clear/thumbnail.png | bin | 0 -> 2070 bytes |
4 files changed, 71 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 | |||