# How to change the region of windowed D3D8 device

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

## Recommended Posts

How to change the region of windowed D3D8 device instead of just stretching/shrinking the 3D scene linearly, when change the window size? ============== Best Regards!

##### Share on other sites
Check:

IDirect3DDevice9::SetViewport(...)
IDirect3DDevice9::GetViewport(...)
and the D3DVIEWPORT9 structure.

I *think* that's what you're looking for?

##### Share on other sites
You need to reset your device.

Before resetting you have to release non-managed ressources and after resetting you ought to acquire them anew.

Take a look at the sample framework, it does that quite good.

##### Share on other sites
I have try the both method you've pointed out
1) try to change the viewport,

D3DVIEWPORT8 Viewport;ZeroMemory(&Viewport, sizeof(Viewport));RECT rect;::GetClientRect(m_hWnd, &rect);	Viewport.Height = static_cast<FLOAT>(w);Viewport.Width  = static_cast<FLOAT>(h);Viewport.MaxZ = 1000;Viewport.MinZ = 0.001;Viewport.X = 0;Viewport.Y = 0;g_pd3dDevice->SetViewport(&Viewport);

2) try to reset the device.(I have no resource to release, so the code is as below)

HRESULT hrD3DDISPLAYMODE d3ddm;hr = g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);	if(FAILED(hr)) {    return hr;}D3DFORMAT d3dformat = D3DFMT_D16;D3DPRESENT_PARAMETERS d3dparam;ZeroMemory(&d3dparam, sizeof(d3dparam));d3dparam.BackBufferFormat = d3ddm.Format;d3dparam.Windowed = TRUE;d3dparam.hDeviceWindow    = g_hwnd;d3dparam.EnableAutoDepthStencil = TRUE;d3dparam.AutoDepthStencilFormat = d3dformat;d3dparam.SwapEffect = D3DSWAPEFFECT_DISCARD;g_pd3dDevice->Reset(&d3dparam);

but it seems no effect.
I am wonder I have not explained the effect I want to get. I want to know that using the windowed d3d device, and when the window is resized, I do not want the 3d scene zoom in/out, I want the 3d scene range enlarge/diminish and the 3d object at the same size.

[Edited by - Coder on August 27, 2004 10:01:00 AM]

##### Share on other sites
If I understand, you would have to adjust the field of view (FOV) to match the new window width and height. Modifying the FOV would keep the center of the screen the same, expanding in every direction. For instance, if a sphere is in the top, left corner, and you resize the window and change the FOV, the sphere will be closer to the center of the window now. It would expand the scene on all sides outward.

You would still have to reset the viewport also.

I'm not sure if this is entirely correct, as I haven't done it, but it seems like it would be the solution, but then again it's late and I'm tired, so sorry if it only causes the scene to "Zoom" in and out.

Chris

##### Share on other sites
Thanks for all your replies, but I still can not get the solution, it seems hard for the windowed device to get this effect.

##### Share on other sites
WHat supernat is saying is thatyou have to change the projection matrix to match the new field of view (FOV).

Device->SetWorld( D3DTS_PROJECTION, ... );

I think that is what you want.

##### Share on other sites
Yes, sorry for that! I did mean modify the projection transform. I kind of just assumed you use the D3DX FOV function to setup your projection matrix. Oops. Anyway, that should do the trick, but the calculations might be a little tricky.

Chris

##### Share on other sites
Here is the code I've found to work for the most part. I haven't tried it in all cases.

  RECT rClientArea;  GetClientRect(hWindowHandle, &rClientArea);  uiWidth = rClientArea.right - rClientArea.left;  uiHeight = rClientArea.bottom - rClientArea.top;  ppPresentParameters.BackBufferWidth = uiWidth;  ppPresentParameters.BackBufferHeight = uiHeight;  pViewManager->GetActivePerspective()->SetFovLH(PI/4*uiHeight/1024, ((float)uiWidth)/uiHeight,                                                  1.0f, 1000.0f);

Here, replace 1024 with the max resolution of the current display. i.e. if you are running the desktop mode at 800x600, put 600 in here. Also, you may want to reset your D3D device (because you are changing the BackBuffer width and height...but you probably already do this.

Hope that helps!
Chris

EDIT: I don't know if DX8 function is different, but this is calling the D3DXMatrixPerspectiveFovLH function. The first parameter is FOV, second is Aspect Ratio, then Near Clip and then Far Clip.

##### Share on other sites
also Opalm, I just realized that when you are resetting your d3d device, you ar enot changing the BackBufferWidth and BackBufferHeight to the new window width and height. You should do that as well as remake the projection matrix.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634060
• Total Posts
3015300
×