1

In SDL2 -- is there a good way to detect a tablet versus phone or determine the screen size (physical screen size --- inches/cm/etc.)?

I want to detect small screens and enlarge button sizes.

I'm looking for the SDL2 way of doing this, preferably, since it doesn't matter whether the device is Android/iPhone/etc.

B. Nadolson
  • 2,988
  • 2
  • 20
  • 27

1 Answers1

1

See this SDL2 function: https://wiki.libsdl.org/SDL_GetDisplayDPI

By getting the resolution and getting the physical DPI, you can get the screen size in inches.

Your specific question is discussed on their bug tracker here:

https://bugzilla.libsdl.org/show_bug.cgi?id=2473

There are some older SO questions that came up empty handed: iOS get physical screen size programmatically?

Community
  • 1
  • 1
Chris Beck
  • 15,614
  • 4
  • 51
  • 87
  • Thanks! That's exactly the API I was looking for, but couldn't find. The API looks very new, I'm sure I could code around the iOS limitation which has [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone, etc.. – B. Nadolson Sep 17 '15 at 21:03
  • Yeah, I didn't know it existed until I looked for it -- be careful though, it says in docs that it only works "if dpi info is available" so you might have to have some fallback plan or something – Chris Beck Sep 17 '15 at 21:58
  • 1
    I've used SDL off and on for several years. In recent times (i.e. SDL2), they are very forward-oriented. And often there are pleasant surprises in the changelogs (case in point, a brilliant blocking "MessageBox" for Android -- writing a blocking messagebox for Android is a major nightmare and Android bends over backwards to make it virtually impossible). But like many rapidly evolving projects, the documentation is thin especially on the bleeding edge. And it is 10x easier to find answers on StackOverflow than SDL2 forums. – B. Nadolson Sep 17 '15 at 22:13
  • Hm, I'm getting a "That operation is not supported" error on an android phone in sdl version 2.0.5 when I SDL_GetDisplayDPI. I wonder why. – mako Aug 31 '17 at 06:14