Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: hellfire on October 21, 2008

Title: screen aspect ratio
Post 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...?

Title: Re: screen aspect ratio
Post by: Shockwave on October 21, 2008
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;

Code: [Select]
    XXX=GetSystemMetrics(SM_CXSCREEN)
    yyy=GetSystemMetrics(SM_CYSCREEN)

and then setting up the aspect ratio of the window like this;

Code: [Select]
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.
Title: Re: screen aspect ratio
Post by: hellfire on October 21, 2008
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?
Title: Re: screen aspect ratio
Post by: Clyde on October 21, 2008
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?
Title: Re: screen aspect ratio
Post by: benny! on October 21, 2008
@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/)
Title: Re: screen aspect ratio
Post by: hellfire on October 21, 2008
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.
Title: Re: screen aspect ratio
Post by: Clyde on October 21, 2008
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:
Code: [Select]
' 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.
Title: Re: screen aspect ratio
Post by: Shockwave on October 21, 2008
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;

Code: [Select]
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))   
Title: Re: screen aspect ratio
Post by: Clyde on October 21, 2008
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.
Title: Re: screen aspect ratio
Post by: Shockwave on October 21, 2008
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.
Title: Re: screen aspect ratio
Post by: Jim on October 22, 2008
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
Code: [Select]
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
Title: Re: screen aspect ratio
Post by: hellfire on October 22, 2008
There's not particularly much to find there:
Quote
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...
Title: Re: screen aspect ratio
Post by: Jim on October 22, 2008
Rats!  If I look under Default_Monitor I see that too.  But if I look at the specific screens I see the EDID.

Jim


Title: Re: screen aspect ratio
Post by: Rbz on October 22, 2008
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.



Title: Re: screen aspect ratio
Post by: Shockwave on October 23, 2008
Wow, a non-pouetized post at Pouet! You just found the needle in the haystack rbz.
Title: Re: screen aspect ratio
Post by: Clyde on October 23, 2008
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?