Sign in to follow this  

DirectX in-window resolution error

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been experiencing an odd effect with a program I have written recently. It's a directX window that can go from windowed mode to full screen with a key-board hotkey. The issue is that when the full screen mode returns to window mode, the window size changes thus affects the directX client space resolution. I have included and commented my code below for others to see. Any suggestions?
		// Go into full screen
		if(full)
		{
			// Check to see if we are not already in fullscreen
			if(fullScreen)
				return;

			// Get the current system resolution:
			int width = GetSystemMetrics(SM_CXSCREEN);
			int height = GetSystemMetrics(SM_CYSCREEN);

			// Backup the original size and pos
			windowPosition = getWindowPosition();

			// Set the window settings to full screen
			d3dpp.Windowed = false;
			d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
			d3dpp.BackBufferWidth = width;
			d3dpp.BackBufferHeight = height;

			// Set window format to be more "full screen friendly"
			SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP);

			// Update the windows position
			SetWindowPos(hWnd, HWND_TOP, 0, 0, width, height, SWP_NOZORDER | SWP_SHOWWINDOW);

			// We reset any and all devices
			//onResetDevice();
		}
		else
		{
			// Are we already in window mode?
			if(!fullScreen)
				return;

			// We lost any and all devices
			//onLostDevice();

			// Set the window settings to full screen
			RECT r = {0, 0, windowSize.x, windowSize.y};
			AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, false);

			// Set the window settings to windowed
			//ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
			d3dpp.Windowed = true;
			d3dpp.BackBufferWidth = windowSize.x;
			d3dpp.BackBufferHeight = windowSize.y;
			d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

			// Set window format to be back to a window
			SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW); //WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU

			// Update the windows position
			//SetWindowPos(hWnd, HWND_TOP, windowPosition.x, windowPosition.y, windowSize.x + 2*GetSystemMetrics(SM_CXDLGFRAME), windowSize.y + 2*GetSystemMetrics(SM_CYDLGFRAME)+GetSystemMetrics(SM_CYCAPTION), SWP_NOZORDER | SWP_SHOWWINDOW);
			//SetWindowPos(hWnd, HWND_TOP, windowPosition.x, windowPosition.y, windowSize.x + extraWindowWidth, windowSize.y + extraWindowHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
			SetWindowPos(hWnd, HWND_TOP, 0, 0, r.right, r.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
			
			// We reset any and all devices
			//onResetDevice();
		}


Share this post


Link to post
Share on other sites
Its a good sugestion! But I have tried that in the past and it does not work. I've copied over that code just to make sure I am doing it correctly:


// Reset device handlers
onLostDevice();
direct3DDevice->Reset(&d3dpp);

onResetDevice();
resetRenderState();


When I resize it to full screen, I size the new buffers to the system width and height (so lets say 1680 by 1050) and then when I size it back to the window I set it to 800 by 600 yet it is slightly off causing a small distortion almost as if the image is 'out of focus'...

Share this post


Link to post
Share on other sites
Quote:
Original post by nint22
When I resize it to full screen, I size the new buffers to the system width and height (so lets say 1680 by 1050) and then when I size it back to the window I set it to 800 by 600 yet it is slightly off causing a small distortion almost as if the image is 'out of focus'...
You need to pass SWP_FRAMECHANGED as a flag to SetWindowPos() to inform Windows that the window style needs updated.

I assume this problem only happens when coming from fullscreen to windowed? D3D will change the window style to popup internally when you go to fullscreen mode, but it won't restore it when you come out of fullscreen mode.

Share this post


Link to post
Share on other sites
Thank you, I think I understand the problem and fixed it. The only question I have left is in my Direct3D properties struct, should I set the width and height both back to 0 when I go from full-screen to windowed?

Share this post


Link to post
Share on other sites

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this