sdl3.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <stdbool.h>
  2. #include <SDL3/SDL.h>
  3. struct app {
  4. int win_w;
  5. int win_h;
  6. SDL_Window *win;
  7. SDL_Renderer *ren;
  8. bool running;
  9. };
  10. int
  11. main(int argc, char *argv[])
  12. {
  13. struct app app = {0};
  14. app.win_w = 800;
  15. app.win_h = 600;
  16. app.running = true;
  17. SDL_Init(SDL_INIT_VIDEO);
  18. SDL_CreateWindowAndRenderer("Title", app.win_w, app.win_h, 0, &app.win, &app.ren);
  19. while ( app.running ) {
  20. SDL_Event e;
  21. event_loop:
  22. if ( ! SDL_PollEvent(&e) ) {
  23. goto event_loop_out;
  24. }
  25. switch( e.type ) {
  26. case SDL_EVENT_QUIT:
  27. app.running = false;
  28. goto event_loop_out;
  29. }
  30. goto event_loop;
  31. event_loop_out: ;
  32. SDL_SetRenderDrawColor(app.ren, 0xFF, 0, 0, 0xFF);
  33. SDL_RenderClear(app.ren);
  34. {
  35. SDL_FRect rect = {0, 0, 10, 10};
  36. rect.x = (((float)app.win_w) - rect.w) / 2.0f;
  37. rect.y = (((float)app.win_h) - rect.h) / 2.0f;
  38. SDL_SetRenderDrawColor(app.ren, 0x00, 0xFF, 0, 0xFF);
  39. SDL_RenderFillRect(app.ren, &rect);
  40. }
  41. SDL_RenderPresent(app.ren);
  42. }
  43. SDL_DestroyWindow(app.win);
  44. SDL_DestroyRenderer(app.ren);
  45. SDL_Quit();
  46. (void) argc; (void) argv;
  47. return 0;
  48. }