There is not a great deal of solid documentation to be found about Glut’s
GameMode. I found the following on the web but I wonder if it is a reliable
explanation of how GameMode should function? Most examples merely show the
application entering GameMode and never returning. I have an application
that needs to go full-screen and also return to decorated window mode. I’m
working with freeglut 2.4.0 on both Win XP and Linux Ubuntu and with a
variety of graphics hardware Nvidia 8800 to Intel 945GM. I get erratic
behaviour – sometimes the return from GameMode has the video driver very
confused and a system has to be restarted – on another platform the return
takes several seconds.
–quote:
When game mode is entered, certain GLUT functionality is disable to
facilitate high-performance fullscreen rendering. GLUT pop-up menus are not
available while in game mode. Other created windows and subwindows are not
displayed in GLUT game mode. Game mode will also hide all other applications
running on the computer’s display screen. The intent of these restrictions
is to eliminate window clipping issues, permit screen display format
changes, and permit fullscreen rendering optimization such as page flipping
for fullscreen buffer swaps.
The value returned by glutEnterGameMode is a unique small integer identifier
for the fullscreen window. The range of allocated identifiers starts at one.
This window identifier can be used when calling glutSetWindow.
After leaving game mode, the GLUT functionality disabled in game mode is
available again. The game mode window (and its OpenGL rendering state) is
destroyed when leaving game mode. Any windows and subwindows created before
entering the game mode are displayed in their previous locations. The OpenGL
state of normal GLUT windows and subwindows is not disturbed by entering
and/or leaving game mode.
–unquote
Here’s a code fragment with my two functions the first to switch to full
screen the second to return. I had a problem with just entering and leaving
GameMode so I explicitly destroy the current window before entering GameMode
and I explicitly create a new window after returning from GameMode. My
application only has one window. The callbacks are re-registered after
entering GameMode and whenever a new window is created.
If I knew the design intent I could write explicitly for that and then start
debugging the particular OS and hardware issues that may be present.
Clive McCarthy
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
void switch_to_full_screen(void)
{
char mode_string[24];
full_screen = TRUE;
sprintf(mode_string, “%dx%d:32@60”, glutGet(GLUT_SCREEN_WIDTH),
glutGet(GLUT_SCREEN_HEIGHT));
glutGameModeString(mode_string);
if(glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
{
printf("GameMode %s is possible
", mode_string);
glutDestroyWindow(glut_pane_id); // destroys the current graphics window
glutEnterGameMode();
glut_OpenGL_call_backs();
glutSetCursor(GLUT_CURSOR_NONE); // hide the cursor
}
else
{
printf("GameMode %s NOT possible
", mode_string);
glutFullScreen();
}
#ifdef UBUNTU_PORT
system(“wmctrl -r"FourteenthStreetStudio” -b
add,fullscreen,skip_taskbar");
#endif
if(glutGameModeGet(GLUT_GAME_MODE_ACTIVE))
{
printf("GameMode is now active…
");
}
else
{
//printf("GameMode is NOT active
");
}
OpenGL_error_check(FILE, LINE);
glutPostRedisplay();
}
/*------------------------------------------------------------------------------
set the window’s width and position for debugging
Window managers (including gnome)
adhere to a standard interface, the EWMH/NetWM specification.
This allows programs that remote-control their functionality.
And fortunately, someone already has written one called “wmctrl”.
------------------------------------------------------------------------------*/
#ifdef FREEGLUT
#define WINDOW_X_ORIGIN 0
#define WINDOW_Y_ORIGIN 0
#else
#define WINDOW_X_ORIGIN 4
#define WINDOW_Y_ORIGIN 24
#endif
void set_debug_window_size(void)
{
int screen_width, screen_length;
full_screen = FALSE;
if(glutGameModeGet(GLUT_GAME_MODE_ACTIVE))
{
printf("returning from GameMode
");
glutLeaveGameMode();
glut_pane_id = glutCreateWindow(“FourteenthStreetStudio”);
glut_OpenGL_call_backs();
}
#ifdef UBUNTU_PORT
system(“wmctrl -r"FourteenthStreetStudio” -b
remove,fullscreen,skip_taskbar");
#endif
screen_width = glutGet(GLUT_SCREEN_WIDTH);
screen_length = glutGet(GLUT_SCREEN_HEIGHT);
switch(screen_width)
{
case 3840: // dual screen WUXGA
glutPositionWindow(WINDOW_X_ORIGIN + (screen_width / 2),
WINDOW_Y_ORIGIN);
glutReshapeWindow(1824, 1140); // 16:10
break;
case 3200: // dual screen UXGA
glutPositionWindow(WINDOW_X_ORIGIN + (screen_width / 2),
WINDOW_Y_ORIGIN);
glutReshapeWindow (1584, 990); // 16:10
break;
etc. etc.