Getting aspect ratio of a monitor

Started by
20 comments, last by Lightrocker 19 years, 11 months ago
Is it possible to retrieve the aspect ration of a monitor? I need this to project scenes and graphical user interfaces correctly to the screen, because there are some computers, which got a widescreen monitor. Dividing resolution width by height can result in wrong values (e.g. for 1280x1024 -> 5:4 and not 4:3). So I need a way to get the correct aspect ratio of the monitor. Thanks!
Advertisement
1280/1024 == 5/4 == 1.25
1024/768 == 4/3 == 1.3333

else, the user has to specify it (means if the screen is native for 1280x1024 but runs at 1024x768, then the whole image would be deformed anyways)



If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

The aspect ration, which is set in a projection matrix, should not depend on the resolution but the real monitor. If there is a 4:3 monitor, then I want to set 4:3 also for non-4:3 resolutions like 1280x1024. And if there is a widescreen monitor, then I want to set its real aspect ratio and not the one of the user-defined resolution.

Is it possible? I did not find a method to get it.
If you are using windows then check out the function GetDeviceCaps
If you use a projection matrix built with a correct aspect ratio in mind and you don''t do any direct blitting of pixels, then you won''t have a problem. For 3d graphics, this is a non issue.

If you have a 2D interface or view images, things get weird.
quote:Original post by GameCat
If you use a projection matrix built with a correct aspect ratio in mind and you don''t do any direct blitting of pixels, then you won''t have a problem. For 3d graphics, this is a non issue.

It''s not a non-issue in the case the original poster was concerned about - widescreen monitors. The vast majority of users have standard 4:3 monitors but there are widescreen monitors out there with a 16:9 aspect ratio and also monitors that can be rotated to give a portrait display with a 3:4 aspect ratio. Monitors with non-standard aspect ratios may well have non-square pixels in many video modes so you can''t automatically calculate the correct aspect ratio based on the screen resolution (that doesn''t work in the inexplicably popular 1280x1024 screen mode on a standard monitor for example). As far as I know all displays are one of 4:3, 16:9 or 3:4 and 3:4 displays can always (I believe) be rotated to a standard 4:3 mode so the easiest thing to do is probably to let the user specify the aspect ratio of their monitor as either 4:3 or 16:9 and use that regardless of the resolution.

Game Programming Blog: www.mattnewport.com/blog

mattnewport is right. I have no problems with displaying two-dimensional images or interfaces, if I have got the correct aspect ratio. I hoped, that there is a Windows API function, which returns the dimension or the aspect ratio of the monitor. GetDeviceCaps is not doing so.
So a user definition seems to be the only way, but I found out that my desktop TFT monitor has got a 5:4 aspect ratio while my CRT and my laptop TFT are 4:3 ones. Does anybody know, if there are some other monitors than 16:9, too?
Out of curiosity, how did you verify that GetDeviceCaps does not work? I am asking since (years ago) I wrote an app where I wanted stuff to appear the same size on screen as the dimensions specified and I used it - seemed to work with the limited tests I did. Thus I simply cut/paste the code in my gl app thinking it would.

I did notice that ASPECTX/ASPECTY returns a small integer and probably is rounded off so I chose to use HORZSIZE/VERTSIZE (since they were in mm) and did my calculations off there.

I was assuming that (if the user has the proper monitor type in Display Properties) that everything would work fine.

Guess I should get off my lazy butt and haul this computer in the other room and try it on my widescreen DLT with that DVI connector aching to be used. Then I''ll know for sure.
One thing I would suggest is to just use the desktop resolution that the user is normally running off. I know that''s not really what you want to do, but think about it this way.... If the user is running a res that gives a 4:3 aspect ratio, then that is what the user is comfortable with, and most likely is the proper ratio for his/her monitor.. If the user has a widescreen, then the ratio will most likely represent that..
Michael RhodesTiger Studios Web Designhttp://tigerstudios.net
@JotDot:

GetDeviceCaps() using HORZSIZE/VERTSIZE results in 4:3 for resolutions like 640x480, 800x600, 1024x768... and 5:4 for 1280x1024 and not real monitor aspect ratio. I already tried that.

@mrhodes:

The GUI of Windows is working another way than I want for my games, in which the GUI should be arranged the same way for the same monitor in every possible resolution. In Windows there fits more information into the screen the higher the resolution is. I only want a higher quality for a higher resolution.

This topic is closed to new replies.

Advertisement