Android window/display size in points

On an iphone6 I get 375x667 from SDL_GetWindowSize (the window size in points) and 750x1334 from SDL_GL_GetDrawableSize. This is an implied render scale of 2 (on a 6+ it’s 3x render scale), see here (http://www.paintcodeapp.com/news/iphone-6-screens-demystified). This makes it easy for me to figure out how to scale up/down the UI elements I’m drawing so it works correctly on various phones/desktops/laptops (a macbook retina correctly returns 2x the window size as the drawable size as well). I’m doing all my rendering with opengl.

On Android (a galaxy sIII) I do the same thing and get 1080x1920 from both SDL_GetWindowSize and SDL_GL_GetDrawableSize. Meaning, SDL_GetWindowSize returns pixels, not points. How can I figure out how to properly scale my UI across lots of android devices?

I don?t think SDL?s APIs have a way to get that information on Android (yet?), unfortunately.

You could use the Android JNI. Here?s some code that gets the density scale using it (it might need some tweaks to work in other codebases though): https://bitbucket.org/rude/love/src/78ae516b9b911ce6db71d08da553f855832dde07/src/common/android.cpp?fileviewer=file-view-default#android.cpp-70 https://bitbucket.org/rude/love/src/78ae516b9b911ce6db71d08da553f855832dde07/src/common/android.cpp?fileviewer=file-view-default#android.cpp-70> On Sep 11, 2015, at 2:10 PM, divad wrote:

On an iphone6 I get 375x667 from SDL_GetWindowSize (the window size in points) and 750x1334 from SDL_GL_GetDrawableSize. This is an implied render scale of 2 (on a 6+ it’s 3x render scale), see here http://www.paintcodeapp.com/news/iphone-6-screens-demystified. This makes it easy for me to figure out how to scale up/down the UI elements I’m drawing so it works correctly on various phones/desktops/laptops (a macbook retina correctly returns 2x the window size as the drawable size as well). I’m doing all my rendering with opengl.

On Android (a galaxy sIII) I do the same thing and get 1080x1920 from both SDL_GetWindowSize and SDL_GL_GetDrawableSize. Meaning, SDL_GetWindowSize returns pixels, not points. How can I figure out how to properly scale my UI across lots of android devices?


SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yes, I can second that you should use displayMetrics via the JNI. If you
are calling this from native code, you will need to run it on the UI thread
and use a FutureTask to read back the float. Sorry, I don’t own the code I
wrote so I can’t share it in full, but it looks something like this:

FutureTask ft = new FutureTask(new GetDensity(metrics));
this.runOnUiThread(ft);

// later on, declare GetDensity

private static class GetDensity implements Callable

This would be a worthwhile thing to incorporate into SDL in the future as
logical coordinate systems are starting to calcify amongst OS vendors.On Fri, Sep 11, 2015 at 10:22 AM, Alex Szpakowski wrote:

I don?t think SDL?s APIs have a way to get that information on Android
(yet?), unfortunately.

You could use the Android JNI. Here?s some code that gets the density
scale using it (it might need some tweaks to work in other codebases
though):
https://bitbucket.org/rude/love/src/78ae516b9b911ce6db71d08da553f855832dde07/src/common/android.cpp?fileviewer=file-view-default#android.cpp-70

On Sep 11, 2015, at 2:10 PM, divad wrote:

On an iphone6 I get 375x667 from SDL_GetWindowSize (the window size in
points) and 750x1334 from SDL_GL_GetDrawableSize. This is an implied render
scale of 2 (on a 6+ it’s 3x render scale), see here
http://www.paintcodeapp.com/news/iphone-6-screens-demystified. This
makes it easy for me to figure out how to scale up/down the UI elements I’m
drawing so it works correctly on various phones/desktops/laptops (a macbook
retina correctly returns 2x the window size as the drawable size as well).
I’m doing all my rendering with opengl.

On Android (a galaxy sIII) I do the same thing and get 1080x1920 from both
SDL_GetWindowSize and SDL_GL_GetDrawableSize. Meaning, SDL_GetWindowSize
returns pixels, not points. How can I figure out how to properly scale my
UI across lots of android devices?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Great, thanks. I got it working using this.

Alex Szpakowski wrote:> I don???t think SDL???s APIs have a way to get that information on Android (yet?), unfortunately.

You could use the Android JNI. Here???s some code that gets the density scale using it (it might need some tweaks to work in other codebases though): https://bitbucket.org/rude/love/src/78ae516b9b911ce6db71d08da553f855832dde07/src/common/android.cpp?fileviewer=file-view-default#android.cpp-70 (https://bitbucket.org/rude/love/src/78ae516b9b911ce6db71d08da553f855832dde07/src/common/android.cpp?fileviewer=file-view-default#android.cpp-70)

On Sep 11, 2015, at 2:10 PM, divad <@divad (@divad)> wrote:
On an iphone6 I get 375x667 from SDL_GetWindowSize (the window size in points) and 750x1334 from SDL_GL_GetDrawableSize. This is an implied render scale of 2 (on a 6+ it’s 3x render scale), see here (http://www.paintcodeapp.com/news/iphone-6-screens-demystified). This makes it easy for me to figure out how to scale up/down the UI elements I’m drawing so it works correctly on various phones/desktops/laptops (a macbook retina correctly returns 2x the window size as the drawable size as well). I’m doing all my rendering with opengl.On Android (a galaxy sIII) I do the same thing and get 1080x1920 from both SDL_GetWindowSize and SDL_GL_GetDrawableSize. Meaning, SDL_GetWindowSize returns pixels, not points. How can I figure out how to properly scale my UI across lots of android devices?
_______________________________________________SDL mailing listSDL at lists.libsdl.org (SDL at lists.libsdl.org)http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)