|
| 1 | +/* |
| 2 | + Copyright (C) 1997-2025 Sam Lantinga <[email protected]> |
| 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 | +#include <SDL3/SDL.h> |
| 13 | +#include <SDL3/SDL_main.h> |
| 14 | + |
| 15 | +int main(int argc, char *argv[]) |
| 16 | +{ |
| 17 | + SDL_Window *window = NULL; |
| 18 | + SDL_Renderer *renderer = NULL; |
| 19 | + const char *message = "Hello World!"; |
| 20 | + int w = 0, h = 0; |
| 21 | + float x, y; |
| 22 | + bool done = false; |
| 23 | + |
| 24 | + /* Create the window */ |
| 25 | + if (!SDL_CreateWindowAndRenderer("Hello World", 0, 0, SDL_WINDOW_FULLSCREEN, &window, &renderer)) { |
| 26 | + SDL_Log("Couldn't create window and renderer: %s\n", SDL_GetError()); |
| 27 | + return 1; |
| 28 | + } |
| 29 | + |
| 30 | + while (!done) { |
| 31 | + SDL_Event event; |
| 32 | + |
| 33 | + /* Handle events */ |
| 34 | + while (SDL_PollEvent(&event)) { |
| 35 | + if (event.type == SDL_EVENT_KEY_DOWN || |
| 36 | + event.type == SDL_EVENT_MOUSE_BUTTON_DOWN || |
| 37 | + event.type == SDL_EVENT_QUIT) { |
| 38 | + done = true; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + /* Center the message */ |
| 43 | + SDL_GetWindowSize(window, &w, &h); |
| 44 | + x = (float)(w - SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE * SDL_strlen(message)) / 2; |
| 45 | + y = (float)(h - SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE) / 2; |
| 46 | + |
| 47 | + /* Draw the message */ |
| 48 | + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); |
| 49 | + SDL_RenderClear(renderer); |
| 50 | + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); |
| 51 | + SDL_RenderDebugText(renderer, x, y, message); |
| 52 | + SDL_RenderPresent(renderer); |
| 53 | + } |
| 54 | + SDL_Quit(); |
| 55 | + |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
0 commit comments