Sign in to follow this  
Fromethius

Direct3D 9 Window Resizing

Recommended Posts

Fromethius    100
Hey everyone. I'm having this problem when I resize my Direct3D app in windowed mode. If I contract my window (as in make the size less), it contracts perfectly. However, if I expand it, as I'm expanding the window, it attempts to redraw the app, resulting in very ugly effects such as this: http://i192.photobucket.com/albums/z20/Fromethius/wtfROFL.png Of course, after I let go of my left mouse button, it goes back to normal. However, I would prefer those lines didn't appear as I was resizing the app Thanks

Share this post


Link to post
Share on other sites
slowmike    144
Yeah, I'd like to know too. I have the same problem, but I haven't got around to fixing it yet. BTW, is that your artwork? Because it looks great.

Share this post


Link to post
Share on other sites
cabbar    127
from DXUT.cpp

[SOURCE]

// msg loop
case WM_SIZE:
...
else if( GetDXUTState().GetInSizeMove() )
{
// If we're neither maximized nor minimized, the window size
// is changing by the user dragging the window edges. In this
// case, we don't reset the device yet -- we wait until the
// user stops dragging, and a WM_EXITSIZEMOVE message comes.
}
...
case WM_ENTERSIZEMOVE:
// Halt frame movement while the app is sizing or moving
DXUTPause( true, true );
GetDXUTState().SetInSizeMove( true );
break;

case WM_EXITSIZEMOVE:
DXUTPause( false, false );
DXUTCheckForWindowSizeChange();
DXUTCheckForWindowChangingMonitors();
GetDXUTState().SetInSizeMove( false );
break;

[/SOURCE]
[/source]

and when the app is paused it skips rendering (See DXUTRender3DEnvironment()method in DXUT.cpp for the code)

edit: Device Reset is done in WM_EXITSIZEMOVE DXUTCheckForWindowSizeChange (I think). In other words, application resets the device once only in exitsizemove event, for the rest of the time only pauses rendering

Share this post


Link to post
Share on other sites
Fromethius    100
Quote:
Original post by slowmike
Yeah, I'd like to know too. I have the same problem, but I haven't got around to fixing it yet. BTW, is that your artwork? Because it looks great.


Heh. A lot of people ask me that. No it is not mine. I'm merely using it for testing.

Quote:
Original post by cabbar
from DXUT.cpp

*** Source Snippet Removed ***[/source][/source]

and when the app is paused it skips rendering (See DXUTRender3DEnvironment()method in DXUT.cpp for the code)

edit: Device Reset is done in WM_EXITSIZEMOVE DXUTCheckForWindowSizeChange (I think). In other words, application resets the device once only in exitsizemove event, for the rest of the time only pauses rendering


Thanks for the reply. However, I'm not using DXUT. I understand the basic jist of what it says there and I'll try it with my application. If anyone knows the proper solution using Direct3D, however, I'd like to know.

Share this post


Link to post
Share on other sites
brekehan    101
Basically, make a bool called pause. Set it on Resize events and skip rendering when it is set.

WIndows Message Proc or Handler:

case WM_ACTIVATE:
{
// If he window is not active stop rendering
if(WA_INACTIVE == wParam)
m_active = FALSE;

// If the window is being activated start rendering again
else
m_active = TRUE;

break;
}

case WM_ENTERSIZEMOVE:
{
// Halt rendering while the window is being sized or moved
m_active = false;

break;
}

case WM_SIZE:
{
// Pick up possible changes to window style due to maximize, etc.
if(!m_fullscreen && m_window)
m_window_style = GetWindowLong(m_window, GWL_style);

// If the window is minimized stop rendering
if(wParam == SIZE_MINIMIZED)
{
m_active = false;
m_minimized = true;
m_maximized = false;
}

// If the window is being maximized start rendering again
// and adjust the device for possible size changes
else if(wParam == SIZE_MAXIMIZED)
{
m_active = true;
m_minimized = false;
m_maximized = true;
HandleSizeChange();
}

// If the window is restored handle possible size changes
else if(wParam == SIZE_RESTORED)
{
// If it is coming from a maximized state the application is already active
if(m_maximized)
{
m_maximized = false;
HandleSizeChange();
}

// If it is coming from a minimized state start rendering again
else if(m_minimized)
{
m_active = true;
m_minimized = false;
HandleSizeChange();
}

// If we're neither maximized nor minimized, the window size
// is changing by the user dragging the window edges. In this
// case, we don't reset the device yet -- we wait until the
// user stops dragging, and a WM_EXITSIZEMOVE message comes.
}
break;
}

case WM_EXITSIZEMOVE:
{
// Handle any possible size changes
HandleSizeChange();

// Start rendering again
m_active = true;

break;
}

default:
break;



Utility Function:

void GFXApplication::HandleSizeChange()
{
RECT old = m_window_client; // The old client size

// Update window properties
GetWindowRect(m_window, &m_window_bounds);
GetClientRect(m_window, &m_window_client);

// Check if the size changed
if(old.right - old.left != m_window_client.right - m_window_client.left ||
old.bottom - old.top != m_window_client.bottom - m_window_client.top)
{
// A new window size will require a new backbuffer size
m_params.BackBufferWidth = m_window_client.right - m_window_client.left;
m_params.BackBufferHeight = m_window_client.bottom - m_window_client.top;

// Reset the device
if(m_device != NULL)
{
FreeResources();

m_device->Reset(&m_params);

InitResources();
}
}
}



Mail Loop:

while(true)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message==WM_QUIT)
break;

TranslateMessage(&msg); // Translate any accelerator keys
DispatchMessage(&msg); // Send the message to event handler
}

// Process Events
// Must process events when inactive as well as active in order to recieve
// the windows messages to activate again. So, do not move this!
EventManager::GetInstance()->Update();

// Main processing loop
if(m_active)
{
// Render
RenderLoop();
m_frames++;
}

// Do Other Stuff Here

Share this post


Link to post
Share on other sites

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