Sign in to follow this  

How to handle window resizing?!

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

Heya, i'm about to write an editor for my litle game and want to support resizing the viewport of the editor..like every good editor does. :) The thing is, i know that it could archive this with resetting the d3d device each time the window is resized...but this isn't the best solution to me. I read somewhere that you could create the device with the size of the desktop and only set the d3d viewport to the new size of the window. I tried that but every time i resize the window, d3d stretches the rendered output, which is obviously not what i want. Is there a flag or something to prevent this stretching behavior? Maybe there is a third solution to that particular problem... I really hope you guys could give me a litle hint how to archive this :) Mfg Impz0r

Share this post


Link to post
Share on other sites
You could try looking into swap chains. Swap chains can be reset without a full device reset, meaning no cleanup/restore, and nearly instantaneous response.

A common trick is to make a 1x1 backbuffer than you never actaully use (1x1 so that it's technically valid, yet doesn't waste space), and create a swap chain per rendering viewport.

Share this post


Link to post
Share on other sites
Hey,

thanks Namethatnobodyelsetook for you answer!

The trick you mentioned, i'm not quite sure if i understand it correct. You mean i create a d3d device with the size of 1x1 and create then another swap chain with the size of my viewport?!

Maybe you could drop me a line if i'm correct. Thanks in advance!


Mfg Impz0r

Share this post


Link to post
Share on other sites
That's the idea, yeah. It seems that in DX9.0c there may be an issue with this. On the DXDEV list, someone was saying that if they try to create a depth buffer larger than the one specified in the original device, it wouldn't work. It used to work in previous versions of DX. I seem to remember that if you don't make a depth buffer with the device (ie: autodepthstencil = false) then the problem won't occur.

So, make a 1x1 device, without depth buffer. Create additional swap chain of whatever size you want. Create a depth surface of matching size. Query the backbuffer surface of the swap chain. Set render target and depthstencil target to your surfaces. Draw. Present using swap chain present.

Share this post


Link to post
Share on other sites
Personnally, I create the backbuffer of the size of the biggest viewport I need, and then for each viewport I use pD3DDevice->SetViewport and it works fine (tested with 4 different sized viewports).

=[dEkS]=

Share this post


Link to post
Share on other sites
to deks: i tried what you mentioned, atleast i believe it was the same..hum as i wrote within my first post, i tried it, with creating the device with the size of the desktop (because the app can't never be greater than this boundaries) and use this for my viewport. And every single time i resize the viewport i used to set the d3d device viewport with SetViewport(), as you mentioned...but i got a stretched output. Dunno whats wrong here ?

Maybe i did it the worng way, do i have to use a swap chain to archive this?!


Mfg Impz0r

Share this post


Link to post
Share on other sites
Use swap chains - it's the best way to go about this. I use Namethatnobodyelsetook's approach, using a 1x1 fake window (that is never rendered) for device creation and swap chains for all rendering windows. Resizing works very well and no stretching occurs.

You just need to remember that for each swap chain you'll have to create a separate backbuffer and depth-stencil surface that you'll have to reset (re-create) each time the size changes and you reset the swap chain.

You can also limit the number of resets by handling the WM_EXITSIZEMOVE message only (e.g. WM_ENTERSIZEMOVE: disable rendering, WM_EXITSIZEMOVE: reset swap-chain, re-create back buffer and depth-stencil surfaces, enable rendering).

Good luck,
Pat.

Share this post


Link to post
Share on other sites
Heya,

so, i tried the swapchain approach as Namethatnobodyelsetook mentioned first, but i get the same result as using swapchains at all. That means, the rendered output is still stretched..dunno whats wrong with my code.

I do it like this:

1) Create a d3d Device with a size of 1x1
2) Create an additional swapchain with the size of my viewport
3) If the app gets resized, i recreate the swapchain (2) and set the backbuffer and zbuffer
4) Clear the screen
5) Render my stuff...

but as mentioned before, the rendered output is still stretched, although i recreate the swapchain every single time with the new size of the viewport...i'm kinda lost here [help]


Any ideas guys...?!

Mfg Impz0r

Share this post


Link to post
Share on other sites
Well, i got it to work, silly me...i forgot to set the camera size and the aspect respectively to the new viewport size...dang [rolleyes]


Thanks to all!


Mfg Impz0r

Share this post


Link to post
Share on other sites

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