Recommended Posts

I am sure this has probably been answered a hundred times before, but I'm not quite sure what I should Google to find the answer, so I decided it was better just to ask.
I have a windowed Direct3D application. My problem is that if I change the width, height, or overall size of the window: instead of rendering to the new size it renders to the old size then stretches the rendered image to fit the window.
How do I tell Direct3D to use the new size?

0

Share this post

Link to post

Share on other sites

EDIT: Now that I think about it - you really should make it so the window can't be resized manually and just have some type of config file or GUI that allows them to set it to known valid sizes such as 640x480, 800x600, 1024x768, etc.

Share this post

Link to post

Share on other sites

Original post by xsirxxYou mean change the actual resolution? not the window size? Or have the resolution change to match the window size? because Im sure that certain video cards cant run at arbitrary resolutions...

In windowed mode they can.

And yeah, you need to reset your device. Be aware that this also requires you to release and recreate all (well, most) resources that weren't created with D3DPOOL_MANAGED. But if everything was created with D3DPOOL_MANAGED, it's a very simple task to reset the device. (See here for Reset() details.)

I have to let the user resize the window, because it is a tile editor program for a 2d game and if they can't resize the window then it will behave more like a dialog box (I need it to behave like the MDI application that it is). The Direct3D is an additional feature, I do not have the option of letting it define my program (setting the window so it can't be resized would be letting it define the program).

Resetting is not a very attractive solution. Many Direct3D samples allow you to resize the window (almost all of them as a matter of fact) and I know they don't call Reset();,

Share this post

Link to post

Share on other sites

I have done the same and D3D doesn't like it for some reason. I never call SetViewport for that reason.You have no choice to release resources, destroy d3d device, recreate d3d device, reload resources.

Note that GL doesn't have this problem, so if it bothers you too much, then switch.

Resetting is not a very attractive solution. Many Direct3D samples allow you to resize the window (almost all of them as a matter of fact) and I know they don't call Reset();,

Can you explain, in detail, exactly how the above code doesn't work?

The idea of changing the viewport parameters is to have a big enough backbuffer to cover the whole screen if needed, but only use the part of it that is required to fill the current window's area. Obviously, the backbuffer area that isn't shown in the window is wasted video memory, but you do avoid the reset in case of window resizing.