summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/docs/hello.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
committer3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
commit6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch)
tree34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/docs/hello.c
parent8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff)
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/docs/hello.c')
-rw-r--r--src/contrib/SDL-3.2.20/docs/hello.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/docs/hello.c b/src/contrib/SDL-3.2.20/docs/hello.c
new file mode 100644
index 0000000..a825ea1
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/docs/hello.c
@@ -0,0 +1,68 @@
1/*
2 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely.
11*/
12#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */
13#include <SDL3/SDL.h>
14#include <SDL3/SDL_main.h>
15
16static SDL_Window *window = NULL;
17static SDL_Renderer *renderer = NULL;
18
19/* This function runs once at startup. */
20SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
21{
22 /* Create the window */
23 if (!SDL_CreateWindowAndRenderer("Hello World", 800, 600, SDL_WINDOW_FULLSCREEN, &window, &renderer)) {
24 SDL_Log("Couldn't create window and renderer: %s", SDL_GetError());
25 return SDL_APP_FAILURE;
26 }
27 return SDL_APP_CONTINUE;
28}
29
30/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
31SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
32{
33 if (event->type == SDL_EVENT_KEY_DOWN ||
34 event->type == SDL_EVENT_QUIT) {
35 return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
36 }
37 return SDL_APP_CONTINUE;
38}
39
40/* This function runs once per frame, and is the heart of the program. */
41SDL_AppResult SDL_AppIterate(void *appstate)
42{
43 const char *message = "Hello World!";
44 int w = 0, h = 0;
45 float x, y;
46 const float scale = 4.0f;
47
48 /* Center the message and scale it up */
49 SDL_GetRenderOutputSize(renderer, &w, &h);
50 SDL_SetRenderScale(renderer, scale, scale);
51 x = ((w / scale) - SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE * SDL_strlen(message)) / 2;
52 y = ((h / scale) - SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE) / 2;
53
54 /* Draw the message */
55 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
56 SDL_RenderClear(renderer);
57 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
58 SDL_RenderDebugText(renderer, x, y, message);
59 SDL_RenderPresent(renderer);
60
61 return SDL_APP_CONTINUE;
62}
63
64/* This function runs once at shutdown. */
65void SDL_AppQuit(void *appstate, SDL_AppResult result)
66{
67}
68