Beispiel #1
0
status_t
GlutGameMode::Leave()
{
	if (!fActive)
		return B_OK;

	if (fGameModeWorkspace < 0)
		return B_ERROR;

	if (fGameModeWindow) {
		glutDestroyWindow(fGameModeWindow);
		fGameModeWindow = 0;
		if (fPreviousWindow)
			glutSetWindow(fPreviousWindow);
	}

	if (_CompareModes(&fOriginalMode, &fCurrentMode)) {
		// Restore original display mode
		BScreen screen;
		// Make restored mode the default one,
		// as it was before entering game mode...
		screen.SetMode(fGameModeWorkspace, &fOriginalMode, true);
	}

	fActive = false;
	return B_OK;
}
Beispiel #2
0
void restoreWorkspaceResolution()
{
	BScreen screen;
	display_mode displayMode;

	if (screen.GetMode(&displayMode) == B_OK && memcmp(&displayMode,&gDisplayMode,sizeof(display_mode)))
		screen.SetMode(&gDisplayMode);
}
Beispiel #3
0
status_t
GlutGameMode::Enter()
{
	display_mode* mode = _FindMatchingMode();
	if (!mode)
		return B_BAD_VALUE;

	BScreen screen;
	if (!fActive) {
		// First enter: remember this workspace original mode...
		fGameModeWorkspace = current_workspace();
		screen.GetMode(fGameModeWorkspace, &fOriginalMode);
	}

	// Don't make it new default mode for this workspace...
	status_t status = screen.SetMode(fGameModeWorkspace, mode, false);
	if (status != B_OK)
		return status;

	// Retrieve the new active display mode, which could be
	// a sligth different than the one we asked for...
	screen.GetMode(fGameModeWorkspace, &fCurrentMode);

	if (!fGameModeWindow) {
		// create a new window
		fPreviousWindow = glutGetWindow();
		fGameModeWindow = glutCreateWindow("glutGameMode");
		if (!fGameModeWindow)
			return Leave();
	} else
		// make sure it's the current window
		glutSetWindow(fGameModeWindow);

	BDirectWindow *directWindow
		= dynamic_cast<BDirectWindow*>(gState.currentWindow->Window());
	if (directWindow == NULL)
		// Hum?!
		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->SetTitle(name.String());
	directWindow->SetFullScreen(true);
	directWindow->Unlock();

	fDisplayChanged = true;
	fActive = true;

	return B_OK;
}