Atlas - hello.c

Home / ext / SDL / docs Lines: 1 | Size: 2260 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
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#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 69
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.