Sign in to follow this  

Very simple Direct3d question

This topic is 4595 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 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by xsirxx
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...
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by honds

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



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.

Share this post


Link to post
Share on other sites

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