Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

Resizing the window?

This topic is 4491 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 start my d3d app in windowed mode, and when I resize the window I wan't the d3d to respond appropriately, eg not stretch etc. I've tried resetting the device and changing the viewport to the new window size, but it still acts if nothing happened. Heres my source:
if(msg == WM_SIZE) {
      //reset device, font
	font->OnLostDevice();

	LPDIRECT3DSWAPCHAIN9 sc;
	device->GetSwapChain(0, &sc);
	D3DPRESENT_PARAMETERS pp;
	sc->GetPresentParameters(&pp);
	sc->Release();
	device->Reset(&pp);

	font->OnResetDevice();

      //change viewport
	D3DVIEWPORT9 vp;
	device->GetViewport(&vp);
	RECT rect;
	GetClientRect(window, &rect);
	vp.Width = rect.right;
	vp.Height = rect.bottom;
	device->SetViewport(&vp);
}

The viewport doesn't change, even though it looks like i'm changing it properly, and also is it necessary to reset the d3d device? Thanks

Share this post


Link to post
Share on other sites
Advertisement
remember that even though you reset the projection matrix, the back-buffer size isnt changed so the image will be streched.

Share this post


Link to post
Share on other sites
Quote:
Original post by treeway
remember that even though you reset the projection matrix, the back-buffer size isnt changed so the image will be streched.


so what should i do about the back buffer?

Share this post


Link to post
Share on other sites
If you create an additional swapchain and use it instead of the implicit swapchain created during the creation of the device, you won't have to reset the device when the window size changes. Just destroy the swapchain and create a new one with a back buffer of the correct size.

Share this post


Link to post
Share on other sites
how would I go about destroying the swap chain?

This is what I have so far on WM_SIZE:

LPDIRECT3DSWAPCHAIN9 sc;
device->GetSwapChain(0, &sc);

//get present parameters
D3DPRESENT_PARAMETERS pp;
sc->GetPresentParameters(&pp);

//how to destroy the swap chain?
sc->Release();

//new swap chain, is this right?
LPDIRECT3DSWAPCHAIN9 sc2;
device->CreateAdditionalSwapChain(&pp, &sc2);



thanks

Share this post


Link to post
Share on other sites
On reset, when you pass in the presentation params, place the new backbuffer width and height in the parameters. Right now you're getting the old state, resetting, and telling D3D to reset to the same values, which is why it doesn't use a new backbuffer size.

Swapchains allow you to resize quickly, and to have multiple backbuffers to display on different sized windows. Don't destroy the built in swap chain.

If you go the swap chain route, make your device backbuffer some small size so it doesn't use much memory.

Create a swapchain and depth buffer. Get the backbuffer from the swapchain. Get the backbuffer and depth buffer from the device and store them away for reset/resize usage. Set the device's rendertarget to the backbuffer from the swap chain, and set the depth buffer to the one you've created. There is no way to query the swap chain for it's depth buffer, so don't use AutoDepthStencil with it, make your own.

On Resize, tell D3D to use the original backbuffer and depth buffer, in order to release it's references to your surfaces. Release your handles to those surfaces, as D3D added a ref when you queried them. Release your handle to your depth buffer. Release your handle to your swapchain back buffer. Now you've freed your swapchain, and your surfaces, and put D3D back into it's normal state. Now go back and create your swap chain again, following all the same steps you used before.

On Reset, free everything else that needs freeing. Destroy the swap chain as above. Reset. Create the swap chain as above. Create any other items that need creating.

Technically you don't need to ask D3D to use it's builtin backbuffer and depth buffer when doing a resize, but it's probably good form when resetting to keep refcounts straight. If you just do the extra work on resize, you can call the same function on resize as on reset, which is a nice bonus.

Share this post


Link to post
Share on other sites
I ended up just resetting it and changing the back buffer width/height in the present parameters like you said.

The swap chain way looks much too complicated for me, unless someone has some sample code.

Thanks

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!