template.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. if (!SDL_Init(SDL_INIT_VIDEO)) {
  16. SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), NULL);
  17. return SDL_APP_FAILURE;
  18. }
  19. if (!SDL_CreateWindowAndRenderer("examples/CATEGORY/NAME", 640, 480, 0, &window, &renderer)) {
  20. SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create window/renderer!", SDL_GetError(), NULL);
  21. return SDL_APP_FAILURE;
  22. }
  23. return SDL_APP_CONTINUE; /* carry on with the program! */
  24. }
  25. /* This function runs when a new event (mouse input, keypresses, etc) occurs. */
  26. SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event)
  27. {
  28. if (event->type == SDL_EVENT_QUIT) {
  29. return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
  30. }
  31. return SDL_APP_CONTINUE; /* carry on with the program! */
  32. }
  33. /* This function runs once per frame, and is the heart of the program. */
  34. SDL_AppResult SDL_AppIterate(void *appstate)
  35. {
  36. return SDL_APP_CONTINUE; /* carry on with the program! */
  37. }
  38. /* This function runs once at shutdown. */
  39. void SDL_AppQuit(void *appstate)
  40. {
  41. /* SDL will clean up the window/renderer for us. */
  42. }