template.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * This example code $WHAT_IT_DOES.
  3. *
  4. * This code is public domain. Feel free to use it for any purpose!
  5. */
  6. #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */
  7. #include <SDL3/SDL.h>
  8. #include <SDL3/SDL_main.h>
  9. /* We will use this renderer to draw into this window every frame. */
  10. static SDL_Window *window = NULL;
  11. static SDL_Renderer *renderer = NULL;
  12. /* This function runs once at startup. */
  13. SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
  14. {
  15. SDL_SetAppMetadata("Example HUMAN READABLE NAME", "1.0", "com.example.CATEGORY-NAME");
  16. if (!SDL_Init(SDL_INIT_VIDEO)) {
  17. SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
  18. return SDL_APP_FAILURE;
  19. }
  20. if (!SDL_CreateWindowAndRenderer("examples/CATEGORY/NAME", 640, 480, 0, &window, &renderer)) {
  21. SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
  22. return SDL_APP_FAILURE;
  23. }
  24. return SDL_APP_CONTINUE; /* carry on with the program! */
  25. }
  26. /* This function runs when a new event (mouse input, keypresses, etc) occurs. */
  27. SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
  28. {
  29. if (event->type == SDL_EVENT_QUIT) {
  30. return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
  31. }
  32. return SDL_APP_CONTINUE; /* carry on with the program! */
  33. }
  34. /* This function runs once per frame, and is the heart of the program. */
  35. SDL_AppResult SDL_AppIterate(void *appstate)
  36. {
  37. return SDL_APP_CONTINUE; /* carry on with the program! */
  38. }
  39. /* This function runs once at shutdown. */
  40. void SDL_AppQuit(void *appstate, SDL_AppResult result)
  41. {
  42. /* SDL will clean up the window/renderer for us. */
  43. }