+ 1

how can i get window size in pixel ( h, w ) ?

Hello, i can't find a methor nor a library which can help me to get the width and height of a monitor which is cross platform, i'm using sdl2 too. for exemple i want to get the size (pixel) of a smartphone how can i do ? thank you :)

4th Oct 2017, 5:26 PM
Clément BOCAGE
Clément BOCAGE - avatar
4 Antworten
+ 2
I was fiddling with this a while back, still "Private" but I could finish it. It uses a few tricks to try to guess your physical screen size. Let me know...is it correct? https://code.sololearn.com/WjJf4KuaIc0K/?ref=app Sorry, just noticed c++ tag. I'll leave this because it has some Android notes in it (and it answers your "for example" in a way), but I'll have to look for something more specific otherwise. * Logical "window size" is usually an API call (or ask the window object itself) * Physcial "monitor" dimensions usually refers to not-mobiles. MSWindows often stores physical information in Plug' N Play data; Linux may record it in X properties and Android uses categories (see code). * Smartphone details (physical attributes like density and dimensions) are historically a harder problem - entire for-pay libraries are dedicated to figuring this out from user agent strings.
4th Oct 2017, 6:00 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
Not sure about C++ / native code on Android. I dig a lot so just found this (root not required to run "activity manager") $ am get-config The $ is the system prompt. In the output are (for me) two values that reveal the physical dimensions of your screen (along with a lot of other things like language, country, Android screen category (like hdpi, mdpi, xxhdpi, etc): Output: config: ...-stuff...-w9999dp-h9999dp-...stuff-... abi: ...architecture... where the 9's are your screen dimensions.
4th Oct 2017, 7:08 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
your answer is still useful for a beginner like me about dpi, etc etc but indeed it is not the right langage ^^ actually i thought of using a system which get the system ( like windows or linux ) and using the right library. but what is the problem with android ? there is no library/function on c++ which i can get the monitor ? or can i use fullscreen option on smartphone ?
4th Oct 2017, 6:47 PM
Clément BOCAGE
Clément BOCAGE - avatar
+ 1
i see, actually i dug too, and i found some "technique", but not too sur about it, but i will use pre processor to find if i am on windows, unix or android. and using fullscreen for android, and using the right library on unix and windows to get dimension of the monitor, it's because on SDL i wand my app to be 1/4 of the width with a minimum of a xxx pixel and 100% of the height ^^ and actually on java there is the toolkit which return w and h but on c++ there is not :( thank you :)
4th Oct 2017, 7:42 PM
Clément BOCAGE
Clément BOCAGE - avatar