14_display.cpp 800 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <cstdio>
  2. #include <cerrno>
  3. #include <iostream>
  4. #include "simple/graphical/initializer.h"
  5. using namespace simple::graphical;
  6. std::ostream& operator<<(std::ostream& os, display::mode mode)
  7. {
  8. os << to_string(mode.format) << ' '
  9. << mode.size.x() << 'x' << mode.size.y() << '@'
  10. << mode.refresh_rate;
  11. return os;
  12. }
  13. int main() try
  14. {
  15. initializer graphics;
  16. for(auto&& display : graphics.displays())
  17. {
  18. std::cout << "Didplay: " << display.name() << '\n';
  19. for(auto&& mode : display.modes())
  20. {
  21. std::cout << mode;
  22. if(mode == display.current_mode())
  23. std::cout << " <--";
  24. std::cout << '\n';
  25. }
  26. std::cout << '\n';
  27. }
  28. return 0;
  29. }
  30. catch(...)
  31. {
  32. if(errno)
  33. std::perror("ERROR");
  34. const char* sdl_error = SDL_GetError();
  35. if(*sdl_error)
  36. std::puts(sdl_error);
  37. throw;
  38. }