From 6aaedb813fa11ba0679c3051bc2eb28646b9506c Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 30 Aug 2025 16:53:58 -0700 Subject: Update to SDL3 --- .../examples/renderer/18-debug-text/README.txt | 4 ++ .../examples/renderer/18-debug-text/debug-text.c | 80 +++++++++++++++++++++ .../examples/renderer/18-debug-text/thumbnail.png | Bin 0 -> 4344 bytes 3 files changed, 84 insertions(+) create mode 100644 src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/README.txt create mode 100644 src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/debug-text.c create mode 100644 src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/thumbnail.png (limited to 'src/contrib/SDL-3.2.20/examples/renderer/18-debug-text') 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 @@ +This example creates an SDL window and renderer, and draws some text +using SDL_RenderDebugText(). This is not quality text rendering, but it can +be helpful for simple apps, debugging, or showing something in a pinch. + 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 @@ +/* + * This example creates an SDL window and renderer, and then draws some text + * using SDL_RenderDebugText() every frame. + * + * This code is public domain. Feel free to use it for any purpose! + */ + +#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ +#include +#include + +/* We will use this renderer to draw into this window every frame. */ +static SDL_Window *window = NULL; +static SDL_Renderer *renderer = NULL; + +#define WINDOW_WIDTH 640 +#define WINDOW_HEIGHT 480 + +/* This function runs once at startup. */ +SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) +{ + SDL_SetAppMetadata("Example Renderer Debug Texture", "1.0", "com.example.renderer-debug-text"); + + if (!SDL_Init(SDL_INIT_VIDEO)) { + SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); + return SDL_APP_FAILURE; + } + + if (!SDL_CreateWindowAndRenderer("examples/renderer/debug-text", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { + SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); + return SDL_APP_FAILURE; + } + + return SDL_APP_CONTINUE; /* carry on with the program! */ +} + +/* This function runs when a new event (mouse input, keypresses, etc) occurs. */ +SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) +{ + if (event->type == SDL_EVENT_QUIT) { + return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ + } + return SDL_APP_CONTINUE; /* carry on with the program! */ +} + +/* This function runs once per frame, and is the heart of the program. */ +SDL_AppResult SDL_AppIterate(void *appstate) +{ + const int charsize = SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE; + + /* as you can see from this, rendering draws over whatever was drawn before it. */ + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ + SDL_RenderClear(renderer); /* start with a blank canvas. */ + + SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); /* white, full alpha */ + SDL_RenderDebugText(renderer, 272, 100, "Hello world!"); + SDL_RenderDebugText(renderer, 224, 150, "This is some debug text."); + + SDL_SetRenderDrawColor(renderer, 51, 102, 255, SDL_ALPHA_OPAQUE); /* light blue, full alpha */ + SDL_RenderDebugText(renderer, 184, 200, "You can do it in different colors."); + SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); /* white, full alpha */ + + SDL_SetRenderScale(renderer, 4.0f, 4.0f); + SDL_RenderDebugText(renderer, 14, 65, "It can be scaled."); + SDL_SetRenderScale(renderer, 1.0f, 1.0f); + SDL_RenderDebugText(renderer, 64, 350, "This only does ASCII chars. So this laughing emoji won't draw: 🤣"); + + SDL_RenderDebugTextFormat(renderer, (float) ((WINDOW_WIDTH - (charsize * 46)) / 2), 400, "(This program has been running for %" SDL_PRIu64 " seconds.)", SDL_GetTicks() / 1000); + + SDL_RenderPresent(renderer); /* put it all on the screen! */ + + return SDL_APP_CONTINUE; /* carry on with the program! */ +} + +/* This function runs once at shutdown. */ +void SDL_AppQuit(void *appstate, SDL_AppResult result) +{ + /* SDL will clean up the window/renderer for us. */ +} + 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 Binary files /dev/null and b/src/contrib/SDL-3.2.20/examples/renderer/18-debug-text/thumbnail.png differ -- cgit v1.2.3