• 13
• 18
• 19
• 27
• 10

# Very simple Direct3d question

This topic is 4690 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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?

##### Share on other sites
You need to reset the d3d device via "Reset(display_params)".. EG:

m_lpDevice->Reset(m_d3dpp);

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.

-Nate S.

##### Share on other sites
You 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...

##### Share on other sites
Quote:
 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.)

##### Share on other sites
It is a windowed application. The resolution does not change. I am rendering to an arbitrary HWND (which happens to be a Borland TPanel) so I do not necessarily know when the window is resized.

This is the code I tried, however, it doesn't seam to work:

	RECT windowRect;	GetWindowRect( window,  &windowRect );	D3DVIEWPORT9 viewport;	viewport.X      = 0;	viewport.Y      = 0;	viewport.Width  = windowRect.right;	viewport.Height = windowRect.bottom;	viewport.MinZ   = 0.0f;	viewport.MaxZ   = 1.0f;	g_pd3dDevice->SetViewport(&viewport);

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();,

[Edited by - honds on May 16, 2005 8:22:14 PM]

##### Share on other sites
P.S.
I have numerous unmanaged resources. So you can see why it would be extremely unattractive for me to call Reset();

##### Share on other sites
"This is the code I tried, however, it doesn't seam to work:"

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.

##### Share on other sites
Quote:
 Original post by hondsThis is the code I tried, however, it doesn't seam to work: RECT windowRect; GetWindowRect( window, &windowRect ); D3DVIEWPORT9 viewport; viewport.X = 0; viewport.Y = 0; viewport.Width = windowRect.right; viewport.Height = windowRect.bottom; viewport.MinZ = 0.0f; viewport.MaxZ = 1.0f; g_pd3dDevice->SetViewport(&viewport);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.