rectangles.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * rectangles.c
  3. * written by Holmes Futrell
  4. * use however you want
  5. */
  6. #include "SDL.h"
  7. #include <time.h>
  8. #include "common.h"
  9. void
  10. render(SDL_Renderer *renderer)
  11. {
  12. Uint8 r, g, b;
  13. /* Come up with a random rectangle */
  14. SDL_Rect rect;
  15. rect.w = randomInt(64, 128);
  16. rect.h = randomInt(64, 128);
  17. rect.x = randomInt(0, SCREEN_WIDTH);
  18. rect.y = randomInt(0, SCREEN_HEIGHT);
  19. /* Come up with a random color */
  20. r = randomInt(50, 255);
  21. g = randomInt(50, 255);
  22. b = randomInt(50, 255);
  23. /* Fill the rectangle in the color */
  24. SDL_SetRenderDrawColor(renderer, r, g, b, 255);
  25. SDL_RenderFillRect(renderer, &rect);
  26. /* update screen */
  27. SDL_RenderPresent(renderer);
  28. }
  29. int
  30. main(int argc, char *argv[])
  31. {
  32. if (SDL_Init(SDL_INIT_VIDEO/* | SDL_INIT_AUDIO */) < 0)
  33. {
  34. printf("Unable to initialize SDL");
  35. }
  36. SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
  37. SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  38. SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  39. int landscape = 1;
  40. int modes = SDL_GetNumDisplayModes(0);
  41. int sx = 0, sy = 0;
  42. for (int i = 0; i < modes; i++)
  43. {
  44. SDL_DisplayMode mode;
  45. SDL_GetDisplayMode(0, i, &mode);
  46. if (landscape ? mode.w > sx : mode.h > sy)
  47. {
  48. sx = mode.w;
  49. sy = mode.h;
  50. }
  51. }
  52. printf("picked: %d %d\n", sx, sy);
  53. SDL_Window *_sdl_window = NULL;
  54. SDL_GLContext _sdl_context = NULL;
  55. _sdl_window = SDL_CreateWindow("fred",
  56. 0, 0,
  57. sx, sy,
  58. SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
  59. SDL_SetHint("SDL_HINT_ORIENTATIONS", "LandscapeLeft LandscapeRight");
  60. int ax = 0, ay = 0;
  61. SDL_GetWindowSize(_sdl_window, &ax, &ay);
  62. printf("given: %d %d\n", ax, ay);
  63. return 0;
  64. }