How to handle window resizing?!

Started by
10 comments, last by Impz0r 19 years, 3 months ago
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
Stay Evil & Ugly!
Advertisement
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.
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
Stay Evil & Ugly!
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.
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]=
Heya,

thanks for your response! I'm heading right into the implementation ;)



Mfg Impz0r
Stay Evil & Ugly!
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
Stay Evil & Ugly!
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.
Aye ok i'll look into it, thanks darookie for your suggestion, and of course thanks to all others :)


Mfg Impz0r
Stay Evil & Ugly!
Personnally, when resizing occurs, I release all D3D resources and recreate the device (which works nicely). Never heard of swapchains though, I'll check into it right now.

=[dEkS]=

This topic is closed to new replies.

Advertisement