• Welcome to Dark Bit Factory & Gravity.
 

screen aspect ratio

Started by hellfire, October 21, 2008

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

hellfire

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...?

Challenge Trophies Won:

Shockwave

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.
Shockwave ^ Codigos
Challenge Trophies Won:

hellfire

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?
Challenge Trophies Won:

Clyde

#3
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?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

benny!

@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/
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

hellfire

Thanks everyone. Calling GetDeviceCaps with HORZSIZE / VERTSIZE did the trick.
Vista seems to offer a more detailed API here.
Challenge Trophies Won:

Clyde

#6
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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Shockwave

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))   
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Shockwave

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.
Shockwave ^ Codigos
Challenge Trophies Won:

Jim

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
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
Challenge Trophies Won:

hellfire

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...
Challenge Trophies Won:

Jim

Rats!  If I look under Default_Monitor I see that too.  But if I look at the specific screens I see the EDID.

Jim


Challenge Trophies Won:

Rbz

I found a topic about this same problem at pouet, maybe it can help a little bit.



Challenge Trophies Won:

Shockwave

Wow, a non-pouetized post at Pouet! You just found the needle in the haystack rbz.
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

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?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: