SDL 3.0
hello.c File Reference
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
+ Include dependency graph for hello.c:

Go to the source code of this file.

Macros

#define SDL_MAIN_USE_CALLBACKS   1 /* use the callbacks instead of main() */
 

Functions

SDL_AppResult SDL_AppInit (void **appstate, int argc, char *argv[])
 
SDL_AppResult SDL_AppEvent (void *appstate, SDL_Event *event)
 
SDL_AppResult SDL_AppIterate (void *appstate)
 
void SDL_AppQuit (void *appstate, SDL_AppResult result)
 

Variables

static SDL_Windowwindow = NULL
 
static SDL_Rendererrenderer = NULL
 

Macro Definition Documentation

◆ SDL_MAIN_USE_CALLBACKS

#define SDL_MAIN_USE_CALLBACKS   1 /* use the callbacks instead of main() */

Definition at line 12 of file hello.c.

Function Documentation

◆ SDL_AppEvent()

SDL_AppResult SDL_AppEvent ( void *  appstate,
SDL_Event event 
)

Definition at line 31 of file hello.c.

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}
@ SDL_EVENT_KEY_DOWN
Definition SDL_events.h:168
@ SDL_EVENT_QUIT
Definition SDL_events.h:89
@ SDL_APP_CONTINUE
Definition SDL_init.h:111
@ SDL_APP_SUCCESS
Definition SDL_init.h:112
Uint32 type
Definition SDL_events.h:988

References SDL_APP_CONTINUE, SDL_APP_SUCCESS, SDL_EVENT_KEY_DOWN, SDL_EVENT_QUIT, and SDL_Event::type.

◆ SDL_AppInit()

SDL_AppResult SDL_AppInit ( void **  appstate,
int  argc,
char *  argv[] 
)

Definition at line 20 of file hello.c.

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}
const char * SDL_GetError(void)
@ SDL_APP_FAILURE
Definition SDL_init.h:113
void SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
bool SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer)
#define SDL_WINDOW_FULLSCREEN
Definition SDL_video.h:189
static SDL_Renderer * renderer
Definition hello.c:17
static SDL_Window * window
Definition hello.c:16

References renderer, SDL_APP_CONTINUE, SDL_APP_FAILURE, SDL_CreateWindowAndRenderer(), SDL_GetError(), SDL_Log(), SDL_WINDOW_FULLSCREEN, and window.

◆ SDL_AppIterate()

SDL_AppResult SDL_AppIterate ( void *  appstate)

Definition at line 41 of file hello.c.

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 */
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);
57 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
58 SDL_RenderDebugText(renderer, x, y, message);
60
61 return SDL_APP_CONTINUE;
62}
bool SDL_RenderPresent(SDL_Renderer *renderer)
bool SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY)
bool SDL_RenderDebugText(SDL_Renderer *renderer, float x, float y, const char *str)
#define SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE
bool SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
bool SDL_RenderClear(SDL_Renderer *renderer)
bool SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
size_t SDL_strlen(const char *str)

References renderer, SDL_APP_CONTINUE, SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE, SDL_GetRenderOutputSize(), SDL_RenderClear(), SDL_RenderDebugText(), SDL_RenderPresent(), SDL_SetRenderDrawColor(), SDL_SetRenderScale(), and SDL_strlen().

◆ SDL_AppQuit()

void SDL_AppQuit ( void *  appstate,
SDL_AppResult  result 
)

Definition at line 65 of file hello.c.

66{
67}

Variable Documentation

◆ renderer

SDL_Renderer* renderer = NULL
static

Definition at line 17 of file hello.c.

Referenced by SDL_AppInit(), and SDL_AppIterate().

◆ window

SDL_Window* window = NULL
static

Definition at line 16 of file hello.c.

Referenced by SDL_AppInit().