Anyway to retrieve screen pixel density?

Hey,

I’ve double checked the documentation and searched in the usual places but can’t seem to find any indication as to if SDL 2.0 has any methods for retrieving the device’s pixel density.

I would like to draw images at their density independent size so that something rendered on say a extra high resolution android device will be the same on any other device such as an iPhone with the same size screen but a different pixel density.

I know that I can make calls through JNI and other platform specific methods, but it would be very convenient if there was an SDL / cross-platform way to get this information.

Any replies much appreciated. :slight_smile:

Thanks

What about using Windows API to get physical dimensions and then easily calculate pixel density(surely you can get display resolution info)?
http://msdn.microsoft.com/en-us/library/windows/desktop/dd144877(v=vs.85).aspx

I never came across such functionality but it’s something I would like too. That’s is useful to detect if we are running on a phone or table alike sizes. I think even the only way, as far as I know (?)------------------------
@DJ_Link

www.david-amador.com

Query Android Java API for the screen size. If it returns ‘Large’ or
higher, consider it a tablet.

Pallav Nawani
IronCode Gaming Private Limited
Website: http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768On Thu, Jun 26, 2014 at 8:21 PM, ^DJ_Link^ <david.djlink at gmail.com> wrote:

I never came across such functionality but it’s something I would like
too. That’s is useful to detect if we are running on a phone or table alike
sizes. I think even the only way, as far as I know (?)


@DJ_Link

www.david-amador.com


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

No, SDL doesn’t have a way to retrieve pixel density. However, you can get
the Desktop resolution. Use that. For example:
DrawWidth = 0.4 * ScreenWidth (40% of screen width).
Now use SDL_Render functions to draw image with the calculated size.

Of course this is not always useful, but you will be surprised how many
times you can get by with just this.

Pallav Nawani
IronCode Gaming Private Limited
Website: http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768On Wed, Jun 25, 2014 at 6:34 PM, zackslash wrote:

Hey,

I’ve double checked the documentation and searched in the usual places but
can’t seem to find any indication as to if SDL 2.0 has any methods for
retrieving the device’s pixel density.

I would like to draw images at their density independent size so that
something rendered on say a extra high resolution android device will be
the same on any other device such as an iPhone with the same size screen
but a different pixel density.

I know that I can make calls through JNI and other platform specific
methods, but it would be very convenient if there was an SDL /
cross-platform way to get this information.

Any replies much appreciated. [image: Smile]

Thanks


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

Thank you for this answer, it may do the job for now :smiley:

Pallav Nawani wrote:> No, SDL doesn’t have a way to retrieve pixel density. However, you can get the Desktop resolution. Use that. For example:

DrawWidth = 0.4 * ScreenWidth (40% of screen width).
Now use SDL_Render functions to draw image with the calculated size.

Of course this is not always useful, but you will be surprised how many times you can get by with just this.

Pallav Nawani
IronCode Gaming Private Limited
Website:??http://www.ironcode.com (http://www.ironcode.com)
Twitter:?? http://twitter.com/Ironcode_Gaming (http://twitter.com/Ironcode_Gaming)
Facebook: http://www.facebook.com/Ironcode.Gaming (http://www.facebook.com/Ironcode.Gaming)
Mobile: 9997478768

On Wed, Jun 25, 2014 at 6:34 PM, zackslash <@zackslash (@zackslash)> wrote:

   	Hey,

I’ve double checked the documentation and searched in the usual places but can’t seem to find any indication as to if SDL 2.0 has any methods for retrieving the device’s pixel density.

I would like to draw images at their density independent size so that something rendered on say a extra high resolution android device will be the same on any other device such as an iPhone with the same size screen but a different pixel density.

I know that I can make calls through JNI and other platform specific methods, but it would be very convenient if there was an SDL / cross-platform way to get this information.

Any replies much appreciated. [Image: http://forums.libsdl.org/images/smiles/icon_smile.gif ]

Thanks


SDL mailing list
SDL 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)

On Windows, I use

HDC hDC = GetWindowDC( NULL );
int hor_mm = GetDeviceCaps( hDC, HORZSIZE );
int ver_mm = GetDeviceCaps( hDC, VERTSIZE );

To check the screen dimensions, though my use case is to get the true
monitor aspect ratio. I don’t know if other platforms have something
similar, and maybe nowadays every monitor/screen have square pixels so
that one could just get the screen resolution to find the aspect ratio.

Cheers,

AndreOn 30/06/2014 10:19, zackslash wrote:

Thank you for this answer, it may do the job for now Very Happy

Pallav Nawani wrote:
No, SDL doesn’t have a way to retrieve pixel density. However, you can
get the Desktop resolution. Use that. For example:
DrawWidth = 0.4 * ScreenWidth (40% of screen width).
Now use SDL_Render functions to draw image with the calculated size.

Of course this is not always useful, but you will be surprised how
many times you can get by with just this.

Pallav Nawani
IronCode Gaming Private Limited
Website:? http://www.ironcode.com
Twitter:? http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768

On Wed, Jun 25, 2014 at 6:34 PM, zackslash <> wrote:

Quote:
Hey,

I’ve double checked the documentation and searched in the usual places
but can’t seem to find any indication as to if SDL 2.0 has any methods
for retrieving the device’s pixel density.

I would like to draw images at their density independent size so that
something rendered on say a extra high resolution android device will
be the same on any other device such as an iPhone with the same size
screen but a different pixel density.

I know that I can make calls through JNI and other platform specific
methods, but it would be very convenient if there was an SDL /
cross-platform way to get this information.

Any replies much appreciated.

Thanks


SDL mailing list

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

I think also this would be very convenient if there was an SDL /
cross-platform way to get this information (in horizontal and vertical
direction separately).

(But that has nothing to do with phone or tablet !)

some information mac/linux :

http://stackoverflow.com/questions/2621439/how-to-get-screen-dpi-linux-mac-programaticallyOn Mon, Jun 30, 2014 at 7:12 PM, Andre Leiradella wrote:

On Windows, I use

HDC hDC = GetWindowDC( NULL );
int hor_mm = GetDeviceCaps( hDC, HORZSIZE );
int ver_mm = GetDeviceCaps( hDC, VERTSIZE );

To check the screen dimensions, though my use case is to get the true
monitor aspect ratio. I don’t know if other platforms have something
similar, and maybe nowadays every monitor/screen have square pixels so that
one could just get the screen resolution to find the aspect ratio.

Cheers,

Andre

On 30/06/2014 10:19, zackslash wrote:

Thank you for this answer, it may do the job for now [image: Very Happy]

Pallav Nawani wrote: No, SDL doesn’t have a way to retrieve pixel
density. However, you can get the Desktop resolution. Use that. For example:
DrawWidth = 0.4 * ScreenWidth (40% of screen width).
Now use SDL_Render functions to draw image with the calculated size.

Of course this is not always useful, but you will be surprised how many
times you can get by with just this.

Pallav Nawani
IronCode Gaming Private Limited
Website:? http://www.ironcode.com
Twitter:? http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768

On Wed, Jun 25, 2014 at 6:34 PM, zackslash <> wrote:

Quote: Hey,

I’ve double checked the documentation and searched in the usual places but
can’t seem to find any indication as to if SDL 2.0 has any methods for
retrieving the device’s pixel density.

I would like to draw images at their density independent size so that
something rendered on say a extra high resolution android device will be
the same on any other device such as an iPhone with the same size screen
but a different pixel density.

I know that I can make calls through JNI and other platform specific
methods, but it would be very convenient if there was an SDL /
cross-platform way to get this information.

Any replies much appreciated.

Thanks


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing listSDL at lists.libsdl.orghttp://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


Sylvain Becker

Le mercredi, 25 juin 2014 ? 14:04, zackslash a ?crit :

I’ve double checked the documentation and searched in the usual places but can’t seem to find any indication as to if SDL 2.0 has any methods for retrieving the device’s pixel density.

There’s no such thing at the moment in SDL 2.0. I would also like to have that see:

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

Best,

Daniel

Ironically the link in that bug report mentions that retrieving the
physical size is not reliable at all (e.g. the monitor could be
lying). Not sure how reliable it is on mobile, but it seems to be
effectively useless on normal computers.

For the record, if this is added maybe having also a hint that lets
the user override the reported size could be a good idea too (this
would make it easier for an user to fix incorrect information without
having to implement it in each program).

2014-07-31 6:26 GMT-03:00, Daniel B?nzli <daniel.buenzli at erratique.ch>:>

Le mercredi, 25 juin 2014 ? 14:04, zackslash a ?crit :

I’ve double checked the documentation and searched in the usual places but
can’t seem to find any indication as to if SDL 2.0 has any methods for
retrieving the device’s pixel density.

There’s no such thing at the moment in SDL 2.0. I would also like to have
that see:

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

Best,

Daniel


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

I can definitely agree on the hint idea. This should probably be
display-specific.

Also, something to perhaps consider:

How would this fare in multi-monitor environments from the application’s
perspective? There’s no guarantee that the displays have the same size at
all. There’s also no guarantee that the user will have the window exclusively
on a certain screen; maybe that should be decided by respecting the screen
with the plurality of the window’s area on it.

I can definitely see the value of this feature on mobile though.–
Melker Narikka

On Thu, Jul 31, 2014 at 1:39 PM, Sik the hedgehog <sik.the.hedgehog at gmail.com> wrote:

Ironically the link in that bug report mentions that retrieving the
physical size is not reliable at all (e.g. the monitor could be
lying). Not sure how reliable it is on mobile, but it seems to be
effectively useless on normal computers.

For the record, if this is added maybe having also a hint that lets
the user override the reported size could be a good idea too (this
would make it easier for an user to fix incorrect information without
having to implement it in each program).

2014-07-31 6:26 GMT-03:00, Daniel B?nzli <daniel.buenzli at erratique.ch>:

Le mercredi, 25 juin 2014 ? 14:04, zackslash a ?crit :

I’ve double checked the documentation and searched in the usual places but
can’t seem to find any indication as to if SDL 2.0 has any methods for
retrieving the device’s pixel density.

There’s no such thing at the moment in SDL 2.0. I would also like to have
that see:

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

Best,

Daniel


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

2014-07-31 8:03 GMT-03:00, Melker Narikka :

Also, something to perhaps consider:

How would this fare in multi-monitor environments from the application’s
perspective? There’s no guarantee that the displays have the same size at
all. There’s also no guarantee that the user will have the window
exclusively
on a certain screen; maybe that should be decided by respecting the screen
with the plurality of the window’s area on it.

Well, the bugzilla entry seems to suggest that the function should
take the display number as a parameter, so it’d be a non-issue (you’d
retrieve the dimensions of each display individually). It’s up to you
to decide how you handle multiple displays.