0

I'm finding it hard to find good sources of information for explanations of DirectX API although I've been looking at the DirectX Documentation for a while.

I'm trying to create a method for a wrapper class for DX9 that changes the resolution during runtime. I've managed to handle this with DirectDraw but I find no information regarding DX9 even though it should be more common.

All I found was a reference to SetDisplayMode, but neither my Direct Object or my DirectX Device has this method.

I'm using DirectX 9.

Example method:

void SetResolution(int width, int height, int depth)
{
   // I have access to DirectX device, object and the window HWND in this class
};

...do I change the HWND window size, or do I handle this in DirectX? I know how to change resolution in a Windows application but no clue how to do it in DX9.

Deukalion
  • 2,516
  • 9
  • 32
  • 50
  • possible duplicate of [How to resize DirectX window efficiently?](http://stackoverflow.com/questions/8764013/how-to-resize-directx-window-efficiently) – Andreas Brinck Jan 11 '13 at 12:50

2 Answers2

5

Try adjusting your D3DPRESENT_PARAMETERS the way you normally would. Something like:

// D3DPRESENT_PARAMETERS is already defined as md3dPP
RECT R ={0, 0, 640, 480}
AdjustwindowRect(&R, WS_OVERLAPPEDWINDOW, false);
md3dPP.BackBufferFormat = D3DFMT_UNKNOWN;
md3dPP.BackBufferWidth = 640;
md3dPP.BackBufferHeight = 480;
md3dPP.Windowed = true;

If you wish, this might also be a good time to change the window style, such as:

SetWindowLongPtr(yourWindowHandle, GWL_STYLE, WS_OVERLAPPEDWINDOW)

// must use SetWindowPos for SetWindowLongPtr changes to take effect
SetWindowPos(yourWindowHandle, HWND_TOP, 100, 100, R.right, R.bottom, SWP_NOZORDER |     SWP_SHOWWINDOW);

Alternatively, if you're using fullscreen:

md3dPP.BackBufferFormat = D3DFMT_X8R8G8B8;
md3dPP.BackBufferWidth = 640;
md3dPP.BackBufferHeight = 480;
md3dPP.Windowed = true;

SetWindowLongPtr(yourWindowHandle, GWL_STYLE, WS_POPUP)

// must use SetWindowPos for SetWindowLongPtr changes to take effect
SetWindowPos(yourWindowHandle, HWND_TOP, 0, 0, 640, 480, SWP_NOZORDER | SWP_SHOWWINDOW);

Either way, follow this up by calling IDirect3DDevice9::Reset. Just make sure you re-initialize your resources when resetting.

So if you defined something like: IDirect3DDevice9 *gd3dDevice;

Use:

gd3dDevice->Reset(&md3dPP);
JayDoe
  • 153
  • 1
  • 5
  • I have something exactly like this, but calling Reset fails each time and the screen goes blank - I have to create a new device each time. – Deukalion Jan 11 '13 at 14:56
1

When creating an IDirect3DDevice9 the resoltuion will be set using the D3DPRESENT_PARAMETERS and the front buffer will be allocated. You cannot change the size of the buffer without recreating the entire device or calling IDirect3DDevice9::Reset.

Carsten
  • 11,287
  • 7
  • 39
  • 62
  • All I get after setting a new D3DPRESENT_PARAMETER and calling Reset() on the device is a white screen, even though I clear the background color to blue each draw. – Deukalion Jan 11 '13 at 13:28
  • Also I set a hotkey to enable/disable fullscreen, but after a few times it just stops responding. – Deukalion Jan 11 '13 at 13:55