Jump to content

  • Log In with Google      Sign In   
  • Create Account


Proper way to handle Alt+Enter?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 30 December 2011 - 11:57 AM

Hello,

It seems DirectX 11 handles Alt+Enter automatically and makes application fullscreen, however without proper parameters it throws warning, therefore I have to fix that. I've done few edits to the code I had and it seems to work correctly (most of the time); in rare cases, when I go from fullscreen to window mode my application's and even other application windows seem to be resized, I've never seen this happen with other games I play, that's why I think I've done something incorrectly. Hopefully you can help me out. Here's the code I have:

Swap Chain initialization:
  DXGI_SWAP_CHAIN_DESC SwapChainDesc;
  SwapChainDesc.BufferCount = 1;
  SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  SwapChainDesc.BufferDesc.Width = 0;
  SwapChainDesc.BufferDesc.Height = 0;
  SwapChainDesc.BufferDesc.RefreshRate.Numerator = 0; // application is created in window mode, so I do not set it now
  SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
  SwapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
  SwapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
  SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  SwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
  SwapChainDesc.OutputWindow = mWindow;
  SwapChainDesc.SampleDesc.Count = 1;
  SwapChainDesc.SampleDesc.Quality = 0;
  SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
  SwapChainDesc.Windowed = 1;
  DXGIFactory->CreateSwapChain(mD3D11Device, &SwapChainDesc, &mDXGISwapChain);

Window Procedure (part):
   case WM_SYSKEYDOWN:
    if(wParam == VK_RETURN && GetAsyncKeyState(VK_MENU)) {
	 mFullscreen = !mFullscreen;
	 mSwapChainResized = true;
	 return 0;
    }
    break;

Swap Chain resizing (this part is between FrameMove() and FrameRender()):
   if(mSwapChainResized) {
    mSwapChainResized = false;
    SwapChainReleased();
    if(mFullscreen) {
	 DXGI_MODE_DESC SwapChainDesc;
	 SwapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	 SwapChainDesc.Width = mFullscreenWidth;
	 SwapChainDesc.Height = mFullscreenHeight;
	 SwapChainDesc.RefreshRate.Numerator = mFullscreenRefreshRate;
	 SwapChainDesc.RefreshRate.Denominator = 1;
	 SwapChainDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
	 SwapChainDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	 mDXGISwapChain->ResizeTarget(&SwapChainDesc);
	 mDXGISwapChain->ResizeBuffers(1, mFullscreenWidth, mFullscreenHeight, DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH);
	 mDXGISwapChain->SetFullscreenState(true, 0);
    }
    else {
	 mDXGISwapChain->SetFullscreenState(false, 0);
	 mDXGISwapChain->ResizeBuffers(1, 0, 0, DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH);
    }
    SwapChainResized();
   }

Thank you in advance.

Sponsor:

#2 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 02 January 2012 - 12:58 AM

*cough* Maybe there's a way to disable Alt+Enter and manually go fullscreen?

#3 Jason Z   Crossbones+   -  Reputation: 4846

Like
1Likes
Like

Posted 02 January 2012 - 03:24 PM

The best practices for handling the fullscreen transitions are available on this page:

http://msdn.microsoft.com/en-us/library/windows/desktop/ee417025(v=vs.85).aspx

Have you checked to see if you are following these guidelines?

#4 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 09 January 2012 - 06:22 PM

Thank you. That cleared up some things, also problems are fixed.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS