Sign in to follow this  
ranmer

How to detect letterboxed video modes (Windows)?

Recommended Posts

ranmer    122
I'm using GLFW and currently coding on a Windows machine. I have aspect correction working in my code so everything looks square in any mode, windowed or fullscreen. Except, a couple of the modes Windows lets me switch to are letterboxed and that throws off my aspect correction. Is there any way to detect if a mode is letterboxed with GL/GLFW?

Edit: Just some notes on what I've figured out so far (still not correcting for letterboxed modes): I'm attempting to find the native resolution (for calculating aspect correction) by enumerating supported modes and picking the one with the widest horizontal resolution and (of all the ones with that maximum width) tallest vertical resolution. That won't necessarily be the mode with the greatest number of pixels, because I noticed some modes are supported that have a greater vertical resolution (but smaller horizontal resolution) than native. I don't know if that's technically correct, but it works on the two machines I have to test on, one with a 16:9 display, and the other with a 16:10 display.

Share this post


Link to post
Share on other sites
dpadam450    2357
[quote] I'm attempting to find the native resolution[/quote]
So let me re-cap: Your switching to a widescreen type mode and your drawings are becoming stretched horizontally?

If so, then how do you not know the resolution already when you call glViewport? When setting up your gl window / windows window, you have to know the width and height to create them.

Share this post


Link to post
Share on other sites
ranmer    122
Here's pseudocode to explain:

[code]
vmlist = get list of supported graphics modes
maxmode = vmlist[0]
foreach mode in vmlist
if (mode.width > maxmode.width) or (mode.width == maxmode.width and mode.height > maxmode.height) then
maxmode = mode
end if
end foreach
nativeAspect = maxmode.width / maxmode.height
...
glfwOpenWindow(... REM: sets mode, opens window, inits GL, etc.
execute window resize callback function manually to set up projection

WINDOW RESIZE CALLBACK (input w and h):
dmode = get desktop mode
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if fullscreen then
aspect = nativeAspect
else
aspect = nativeAspect / (dmode.width / dmode.height) * (w / h)
end if
gluPerspective(90.0, aspect, 0.01, 100.0);
[/code]

For 11 out of the 13 modes Windows supports on my system (or was it 10 out of 13), this works perfectly. For the remaining two or three modes, Windows (or the driver rather) adds black bars to the top and/or bottom of the screen, instead of stretching the image vertically. If I could somehow detect when this is happening in my code, then I could easily adjust my aspect correction formula when that happens, but I know of no way to detect it.

Also, when I said I was attempting to identify the native resolution, I didn't necessarily mean that I'd switch to that mode, merely that I was getting it's dimensions so I could calculate the native aspect ratio.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this