template.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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, SDL_WINDOW_RESIZABLE, &window, &renderer)) {
  21. SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
  22. return SDL_APP_FAILURE;
  23. }
  24. SDL_SetRenderLogicalPresentation(renderer, 640, 480, SDL_LOGICAL_PRESENTATION_LETTERBOX);
  25. return SDL_APP_CONTINUE; /* carry on with the program! */
  26. }
  27. /* This function runs when a new event (mouse input, keypresses, etc) occurs. */
  28. SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
  29. {
  30. if (event->type == SDL_EVENT_QUIT) {
  31. return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
  32. }
  33. return SDL_APP_CONTINUE; /* carry on with the program! */
  34. }
  35. /* This function runs once per frame, and is the heart of the program. */
  36. SDL_AppResult SDL_AppIterate(void *appstate)
  37. {
  38. return SDL_APP_CONTINUE; /* carry on with the program! */
  39. }
  40. /* This function runs once at shutdown. */
  41. void SDL_AppQuit(void *appstate, SDL_AppResult result)
  42. {
  43. /* SDL will clean up the window/renderer for us. */
  44. }