Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Finding screen width and height dynamically in OpenGL GLUT program

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011
    Posts
    2

    Finding screen width and height dynamically in OpenGL GLUT program

    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)

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    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 is one possibility.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,123
    Quote Originally Posted by kindergartenbaby View Post
    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?

    See:

    http://freeglut.sourceforge.net/docs/api.php

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,135
    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:
    Code :
    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:
    Code :
    RECT workarea;
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •