Jump to content
  • Advertisement
Sign in to follow this  
PumpkinPieman

Resizing a surface.

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

Right now I've come to a little problem where I somehow have to resize the screen in my MFC editor, and when I do I want to have the device change its window size so it doesn't stretch the surface out of proportion. I thought of using a swap chain and just killing and creating another one when the window is resized. But then I had problems with my window [MFC] painting whilst the swap chain was destroyed, and it ending up crashing. Since MFC has no real linear flow to the execution of the code(or does it?) nothing I’ve tried has worked. Does anyone know a solution or some type of work around for this kind of problem? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Override the OnPaint message function and only allow it to paint when the device is prepared.

Using MFC shouldn't be any different than using a normal window. Oh, and you can use timers to simulate a game loop. But I don't think that has much to do with your problem.

Share this post


Link to post
Share on other sites
What you must do is that when your main frame receives a WM_SIZE msg, you must release all swapchains. Call reset for the backbuffer. And then recreate the swapchains.

If the main window dont resize but only the client view windows. You need to release thier swapchains, and recreate them with the new size.

This is what im doing using wtl. and it works. For both resizeing the main frame, and resizing the client windows.


Code for resetting device on resizing the main frame:

void graphics_manager_d3d_t::reset(int screen_width, int screen_height, bool fullscreen)
{
// save screen information
m_screen_width = screen_width;
m_screen_height = screen_height;
m_fullscreen = fullscreen;

HRESULT hr = 0;
if(FAILED(hr = m_d3dx_font->OnLostDevice()))
debug_assert(false, DXGetErrorString9(hr));
if(FAILED(hr = m_d3dx_line->OnLostDevice()))
debug_assert(false, DXGetErrorString9(hr));

// release all swapchains
for(std::map<int, swap_chain_t>::iterator iter = m_swap_chain_map.begin(); iter != m_swap_chain_map.end(); ++iter)
iter->second.m_d3d_swap_chain->Release();

// reinitialize the render device if it was lost
D3DPRESENT_PARAMETERS d3dpp = get_present_parameters(m_hwnd, m_screen_width, m_screen_height, m_fullscreen);
if(FAILED(hr = m_d3d_device->Reset(&d3dpp)))
debug_assert(false, DXGetErrorString9(hr));

// recreate swap chains
for(std::map<int, swap_chain_t>::iterator iter = m_swap_chain_map.begin(); iter != m_swap_chain_map.end(); ++iter)
{
swap_chain_t swap_chain = iter->second;

HRESULT hr = 0;
D3DPRESENT_PARAMETERS d3dpp = get_present_parameters(swap_chain.m_hwnd, 0, 0, false);
if(FAILED(hr = m_d3d_device->CreateAdditionalSwapChain(&d3dpp, &swap_chain.m_d3d_swap_chain)))
debug_assert(false, DXGetErrorString9(hr));

iter->second = swap_chain;
}

if(FAILED(hr = m_d3dx_font->OnResetDevice()))
debug_assert(false, DXGetErrorString9(hr));
if(FAILED(hr = m_d3dx_line->OnResetDevice()))
debug_assert(false, DXGetErrorString9(hr));
}



You dont need to reset the device if only the swap chains change size, but not the main window.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!