Jump to content
  • Advertisement
Sign in to follow this  
Opalm

How to change the region of windowed D3D8 device

This topic is 5162 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

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 this post


Link to post
Share on other sites
Advertisement
Check:

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

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

Share this post


Link to post
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 this post


Link to post
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 hr
D3DDISPLAYMODE 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!