Author Topic: screen aspect ratio  (Read 8932 times)

0 Members and 1 Guest are viewing this topic.

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
screen aspect ratio
« 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...?

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17423
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: screen aspect ratio
« Reply #1 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.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: screen aspect ratio
« Reply #2 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?
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: screen aspect ratio
« Reply #3 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?
« Last Edit: October 21, 2008 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: screen aspect ratio
« Reply #4 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/
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: screen aspect ratio
« Reply #5 on: October 21, 2008 »
Thanks everyone. Calling GetDeviceCaps with HORZSIZE / VERTSIZE did the trick.
Vista seems to offer a more detailed API here.
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: screen aspect ratio
« Reply #6 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.
« Last Edit: October 21, 2008 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17423
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: screen aspect ratio
« Reply #7 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))   
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: screen aspect ratio
« Reply #8 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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17423
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: screen aspect ratio
« Reply #9 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.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: screen aspect ratio
« Reply #10 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
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
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: screen aspect ratio
« Reply #11 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...
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: screen aspect ratio
« Reply #12 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


Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: screen aspect ratio
« Reply #13 on: October 22, 2008 »
I found a topic about this same problem at pouet, maybe it can help a little bit.



Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17423
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: screen aspect ratio
« Reply #14 on: October 23, 2008 »
Wow, a non-pouetized post at Pouet! You just found the needle in the haystack rbz.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: screen aspect ratio
« Reply #15 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?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: