View Full Version : Finding screen width and height dynamically in OpenGL GLUT program
07-23-2012, 04:49 AM
In my OpenGL program, in order to run it in fullscreen mode, I'm using the GLUT function glutGameModeString(const char *string).
(where 'string' specifies the screen width,height,pixelDepth and refresh rate)
To make it working in any system,i need to dynamically determine the screen width and screen height of the host system, prior to making the call to 'glutGameModeString' function.
How do I do that?
(I just need to know how to retrieve the screen height and width in windows)
07-23-2012, 10:28 AM
You stop using GLUT and use a system that's designed to be used for this sort of thing. GLUT has no function for this sort of thing, and OpenGL doesn't know of anything outside of the window.
GLFW (http://www.glfw.org/) is one possibility.
07-23-2012, 02:54 PM
In my OpenGL program, in order to run it in fullscreen mode ... To make it working in any system,i need to dynamically determine the screen width and screen height of the host system
What about just using the default:
Per the API docs "glutGameModeString: Specify the display mode that should be entered when GameMode is entered. Default is the current display mode of the monitor on which the GameMode screen will be opened. "
Also, have you looked at: glutFullScreen, glutLeaveFullScreen, glutFullScreenToggle?
07-23-2012, 06:31 PM
Unfortunately GLUT is very limited for this kind of thing - them's the tradeoffs for using a simplified framework.
If, like you say, you're only interested in finding this on Windows, you could break into some Windows API calls. For getting the size of the entire screen, something like this can suffice:
HDC hdc = GetDC (NULL);
width = GetDeviceCaps (hdc, HORZRES);
height = GetDeviceCaps (hdr, VERTRES);
ReleaseDC (NULL, hdc);
That's sometimes not what you want; you may want the size of the working area of the screen (i.e. excluding the taskbar and other similar widgets) in which case something like this will do the job:
SystemParametersInfo (SPI_GETWORKAREA, 0, &workarea, 0);
Both of these have uses other than just for helping with going to and from fullscreen mode; the working area size is particularly useful for setting an upper bound on the largest windowed mode you might wish to support, and can also be used for centering your window properly on the screen.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.