Reuse game mode window on re-enter, and restore previous window, if any,
when leaving game mode. Now a windowed glut app can (re-)enter and leave game mode as much as it wants to. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37903 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -28,7 +28,9 @@ GlutGameMode::GlutGameMode()
|
|||||||
fRefreshRate(-1),
|
fRefreshRate(-1),
|
||||||
fModesList(NULL),
|
fModesList(NULL),
|
||||||
fModesCount(0),
|
fModesCount(0),
|
||||||
fGameModeWorkspace(-1)
|
fGameModeWorkspace(-1),
|
||||||
|
fGameModeWindow(0),
|
||||||
|
fPreviousWindow(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,21 +113,32 @@ GlutGameMode::Enter()
|
|||||||
// a sligth different than the one we asked for...
|
// a sligth different than the one we asked for...
|
||||||
screen.GetMode(fGameModeWorkspace, &fCurrentMode);
|
screen.GetMode(fGameModeWorkspace, &fCurrentMode);
|
||||||
|
|
||||||
// create a new window in full screen
|
if (!fGameModeWindow) {
|
||||||
BString name;
|
// create a new window
|
||||||
name << "Game Mode " << fCurrentMode.virtual_width
|
fPreviousWindow = glutGetWindow();
|
||||||
<< "x" << fCurrentMode.virtual_height
|
fGameModeWindow = glutCreateWindow("glutGameMode");
|
||||||
<< ":" << _GetModePixelDepth(&fCurrentMode)
|
if (!fGameModeWindow)
|
||||||
<< "@" << _GetModeRefreshRate(&fCurrentMode);
|
return Leave();
|
||||||
|
} else
|
||||||
glutCreateWindow(name.String());
|
// make sure it's the current window
|
||||||
|
glutSetWindow(fGameModeWindow);
|
||||||
|
|
||||||
BDirectWindow *directWindow
|
BDirectWindow *directWindow
|
||||||
= dynamic_cast<BDirectWindow*>(gState.currentWindow->Window());
|
= dynamic_cast<BDirectWindow*>(gState.currentWindow->Window());
|
||||||
if (directWindow == NULL)
|
if (directWindow == NULL)
|
||||||
// Hum?!
|
// Hum?!
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
|
// Give it some useless title, except for debugging (thread name).
|
||||||
|
BString name;
|
||||||
|
name << "Game Mode " << fCurrentMode.virtual_width
|
||||||
|
<< "x" << fCurrentMode.virtual_height
|
||||||
|
<< ":" << _GetModePixelDepth(&fCurrentMode)
|
||||||
|
<< "@" << _GetModeRefreshRate(&fCurrentMode);
|
||||||
|
|
||||||
|
// force the game mode window to fullscreen
|
||||||
directWindow->Lock();
|
directWindow->Lock();
|
||||||
|
directWindow->SetTitle(name.String());
|
||||||
directWindow->SetFullScreen(true);
|
directWindow->SetFullScreen(true);
|
||||||
directWindow->Unlock();
|
directWindow->Unlock();
|
||||||
|
|
||||||
@@ -145,6 +158,13 @@ GlutGameMode::Leave()
|
|||||||
if (fGameModeWorkspace < 0)
|
if (fGameModeWorkspace < 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
|
if (fGameModeWindow) {
|
||||||
|
glutDestroyWindow(fGameModeWindow);
|
||||||
|
fGameModeWindow = 0;
|
||||||
|
if (fPreviousWindow)
|
||||||
|
glutSetWindow(fPreviousWindow);
|
||||||
|
}
|
||||||
|
|
||||||
if (_CompareModes(&fOriginalMode, &fCurrentMode)) {
|
if (_CompareModes(&fOriginalMode, &fCurrentMode)) {
|
||||||
// Restore original display mode
|
// Restore original display mode
|
||||||
BScreen screen;
|
BScreen screen;
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ private:
|
|||||||
display_mode fOriginalMode;
|
display_mode fOriginalMode;
|
||||||
int fGameModeWorkspace;
|
int fGameModeWorkspace;
|
||||||
display_mode fCurrentMode;
|
display_mode fCurrentMode;
|
||||||
|
int fGameModeWindow;
|
||||||
|
int fPreviousWindow;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user