Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: hellfire on October 21, 2008
-
Hi everybody,
I'm looking for a reliable way to get the display's *actual* aspect-ratio.
At the moment I expect the pixels to be square and pick the (nearest) corresponding ratio from the desktop-resolution.
So, for example, a 1280x720-display is very likely to be 16:9 - but it's not always true:
My old CRT running at 1280x1024 would result in 5:4 but actually is 4:3.
Another flat-screen runs 1920x1080 (16:9) but is 16:10.
And there are probably even worse examples around.
However, there should be a way to get this information without user-interaction...?
-
I guess that this isn't going to be much help Hellfire, but you've given me so many good pointers in the past that I am going to try anyway.
I've tried to make the pixels seem square in my own things these days by grabbing the desktop resolution with something like;
XXX=GetSystemMetrics(SM_CXSCREEN)
yyy=GetSystemMetrics(SM_CYSCREEN)
and then setting up the aspect ratio of the window like this;
GLUPERSPECTIVE whatever, XXX / YYY, whatever, whatever
But somehow that seems too simple to solve what you are looking for?
I've done some browsing since you posted that topic and been completely confused by a lot of what I found.
Maybe when someone cleverer like rbz or jim comes along they'll have a solution for you.
I hope so.
-
Thanks Shocky, actually that's exactly what I do now ("pick the ratio from the desktop-resolution").
This assumes the pixels to be square - unluckily this isn't the case for some displays :P
But... what then?
-
This is just an idea, are there not commands that can get info for the aspect ratio info from the Graphics card as on mine it has the monitor info, and incorparate that into your getsystemmetric?
-
@hellfire:
Never thought about this issue before - to be honest. But
maybe this is of some help (dont know)
http://lurkertech.com/lg/video-systems/ (http://lurkertech.com/lg/video-systems/)
-
Thanks everyone. Calling GetDeviceCaps (http://msdn.microsoft.com/en-us/library/ms533266(VS.85).aspx) with HORZSIZE / VERTSIZE did the trick.
Vista seems to offer a more detailed API (http://msdn.microsoft.com/en-us/library/ms775232(VS.85).aspx) here.
-
Not meaning at all to topic hijack dude.
Thats quite an interesting set of commands, usefull for my ongoing learning curve of windows api stuff, and centering the main window.
How'd you using this feature btw dude, if I did something along these lines:
' Get actual screen resolution
Dim As Integer WindowWidth=256, WindowHeight=128
Dim As Integer SystemX, SystemY
Dim As Integer CenterX, CenterY
SystemX = cast(WORD,GetSystemMetrics(SM_CXSCREEN)) ' width
SystemY = cast(WORD,GetSystemMetrics(SM_CYSCREEN)) ' height
CenterX = (SystemX - WindowWidth )/2
CenterY = (SystemY - WindowHeight)/2
Or would it not make any difference, with adding the aspect ratio into the equation?
Please move this into a new topic if it's going off the rails.
Cheers,
Clyde.
-
It's still fairly relevant to the topic Clyde, as it's to do with windows..
For a borderless window, centered you could do something like this;
XRES= XRES (IN PIXELS)
YRES= YRES (IN PIXELS)
SystemX = cast(WORD,GetSystemMetrics(SM_CXSCREEN))
SystemY = cast(WORD,GetSystemMetrics(SM_CYSCREEN))
XXX=(XRES-SYSTEM_X)/2
YYY=(YRES-SYSTEM_Y)/2
hDC = GetDC(CreateWindow("Edit", "TITLE", WS_DLGFRAME+WS_POPUP+WS_VISIBLE,xxx, yyy, XRES , YRES, 0, 0, 0, 0))
-
Yeah cheers dude thats along the lines that I've got at the moment.
I wondered if introducing the aspect ratio into that equation would make any difference ( and how if applicable? )
Chars,
Clyde.
-
If you are going to center the window you need to know how wide and how tall the screen is. That bit of code doesn't change the aspect ratio.
I guess that if you knew the screen width and height and you were using some kind of hardware API then you could alter the dimensions of your window to take it into account.
-
Right, the problem is that if one of you guys makes a 640x480 fullscreen demo, and I run it on my 16:10 screen, it all gets stretched by the hardware video scaler in the screen, even though Windows will tell you the pixels are square!
The information should be available via EDID
http://en.wikipedia.org/wiki/Extended_display_identification_data#EDID_1.1_data_format (http://en.wikipedia.org/wiki/Extended_display_identification_data#EDID_1.1_data_format)
I think Windows stores a copy of the EDID information for each monitor under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY
So you should be able either to look up the aspect ratio or the physical dimensions of the screen from there.
Jim
-
There's not particularly much to find there:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY\Default_Monitor
+ 5&c724254&0&11337799&01&00
- DeviceDesc: ""
- Capabilities: 0xe6
- ConfigFlags: 0
- HardwareID: "Monitor\Default_Monitor"
- CompatibleIDs: "*PNP09FF"
- ClassGUID: "{4D36E96E-E325-11CE-BFC1-08002BE10318}"
- Class: "Monitor"
- Driver: "{4D36E96E-E325-11CE-BFC1-08002BE10318}\0003"
- Mfg: "(Standardmonitortypen)"
+ Device Parameters
- BAD_EDID: ""
+ LogConf
+ Control
I guess there should be information in the Device Parameters field?
(which contains 256 bytes of finest zeros)
So I'm wondering where GetDeviceCaps gets my screen dimensions from...
-
Rats! If I look under Default_Monitor I see that too. But if I look at the specific screens I see the EDID.
Jim
-
I found a topic about this same problem at pouet (http://www.pouet.net/topic.php?which=5549&page=1), maybe it can help a little bit.
-
Wow, a non-pouetized post at Pouet! You just found the needle in the haystack rbz.
-
Looks interesting, I guess this applies mostly to full screen productions, and not really windowed orientated.
Btw, Is that post at PN using OGL bits?